8

I was running this code 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();

and I got this below given out.

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)

I am pretty sure that I have not done any typo. This some packaging issue. Does anyone have the idea how to resolve?

4 Answers 4

7

Update: npm uninstall ethereumjs-wallet npm uninstall truffle-hdwallet-provider npm install --save [email protected] npm install --save [email protected]

Credit goes to 2 gentlemen on udemy QA Sarshad and Guang


I tried to install a prior version to ethereumjs-wallet (npm install --save [email protected] or @0.6.0) and this time it starts running but crashes on the async/await as a warning.

No transaction either on etherscan so it seems need to use promises with prior versions < 0.6.1 of ethereumjs-wallet (haven't tried that yet).

[email protected] has a different file structure and hdkey is no longer in its root folder.

2
  • 1
    Thanks for the help. I found the root cause. Ethereum version >0.6.0 has directory issue. Modules like hdkey.js index.js are not in the classpath of the ethereum-walletjs. Releasing team has made a new folder named dist and kept these module in it. So, changing the directory can also solve the problem.
    – kaushik_pm
    Commented Jul 30, 2018 at 7:20
  • @kaushik_pm its better if you can accept an answer or provide one Commented Jul 30, 2018 at 7:54
1

The ethereumwalletjs version > 0.6.0 has some directory problem. They have created dist folder inside the ethereumwallet and kept the hdkey.js and index.js module inside it. That's why this problem occurs. I kept it in direct location of ethereumwallet package and it worked. Now this solution will work for every higher version greater than 0.6.0.

1
  • you answer doesn't indicate how to fix the problem. what does "I kept it in direct location of ethereumwallet package and it worked" mean?
    – ekkis
    Commented Sep 14, 2022 at 0:18
1

As of today (2081-08-07) to get around this issue and use the latest versions you can add these to your package.json and it will work.

"dependencies": {
    ...other bits...
    "ethereumjs-wallet": "^0.6.1",
    "truffle-hdwallet-provider": "^0.0.6",
    ... other bits...
}

or you can update them on the command line:

npm install --save ethereumjs-wallet
npm install --save truffle-hdwallet-provider

I know people prefer to lock versions to stop issues in the future, if so, just omit the ^ at the front of the version numbers. You should get a package-lock.json file anyway when you install the first time which will freeze you stable version numbers anyway.

Best of luck!

0

The solution is that you import hdkey from the ethereumjs-wallet library. hdkey is being exported and it is not the default export.

const {hdkey} = require('ethereumjs-wallet');

const mnemonic = bip39.generateMnemonic();
const seed = bip39.mnemonicToSeedSync(mnemonic);
const hdWallet = hdkey.fromMasterSeed(seed);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.