我在运行这段代码deploy.js
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'***** ****** ********* ********************* ***********',
'https://rinkeby.infura.io/v3/*****************'
);
const web3 = new Web3(provider);
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account', accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({ gas: '1000000', from: accounts[0] });
console.log('Contract deployed to', result.options.address);
};
deploy();下面我把这个发出去了。
node deploy.js
module.js:549
throw err;
^
Error: Cannot find module 'ethereumjs-wallet/hdkey'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\Saurabh\inbox\node_modules\truffle-hdwallet-provider\index.js:2:13)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)我很确定我没有做任何错字。这是一些包装问题。有谁知道怎么解决吗?
发布于 2018-07-30 08:01:29
ethereumwalletjs版本> 0.6.0存在一些目录问题。他们在电子钱包中创建了dist文件夹,并将hdkey.js和index.js模块保存在其中。这就是为什么会出现这个问题。我把它放在空灵钱包包的直接位置,它起了作用。现在,这个解决方案将适用于每一个大于0.6.0的更高版本。
发布于 2018-07-29 11:10:25
更新:npm uninstall ethereumjs-wallet npm uninstall truffle-hdwallet-provider npm install --save ethereumjs-wallet@0.6.0 npm install --save truffle-hdwallet-provider@0.0.3
对udemy QA Sarshad和Guang的2位先生的信用
我试着安装一个早期版本的ethereumjs钱包(npm install --save ethereumjs-wallet@0.5.2或@0.6.0),这一次它开始运行,但在异步/等待上崩溃作为警告。
在以太扫描上也没有任何事务,所以似乎需要使用以前版本< 0.6.1的ethereumjs钱包(还没有尝试过)的承诺。
ethereumjs钱包@0.6.1有不同的文件结构,hdkey不再位于其根文件夹中。
发布于 2018-08-07 00:01:10
从今天(2081-08-07)开始,为了解决这个问题,并使用最新版本,您可以将这些添加到您的package.json中,它将工作。
"dependencies": {
...other bits...
"ethereumjs-wallet": "^0.6.1",
"truffle-hdwallet-provider": "^0.0.6",
... other bits...
}或者您可以在命令行中更新它们:
npm install --save ethereumjs-wallet
npm install --save truffle-hdwallet-provider我知道人们更喜欢锁定版本以在将来停止问题,如果是这样的话,只需在版本号前面省略^。在第一次安装时,您应该得到一个package-lock.json文件,这将冻结您稳定的版本号。
祝你好运!
https://ethereum.stackexchange.com/questions/55390
复制相似问题