0

Generated wallet address using:

let mnemonic = request.body.seed;
const wallet = EthHdWallet.fromMnemonic(mnemonic);
let address = wallet.generateAddresses(1);
console.log(wallet, address);

How can I recover wallet address using mnemonic?

1 Answer 1

0

Yes - except using ethereumjs-wallet not ethereumjs-utils. Using the same mnemonic, with either supporting repo produces the same account address here:

const { EthHdWallet } = require('eth-hd-wallet')
var hdkey = require("ethereumjs-wallet/hdkey")
var bip39 = require("bip39");

const mnemonic = bip39.generateMnemonic(); //generates string
console.log(`mnemonic: ${mnemonic}`);

const wallet = EthHdWallet.fromMnemonic(mnemonic);
let address = wallet.generateAddresses(1);
console.log(`EthHdWallet Address: ${address}`);

bip39.mnemonicToSeed(mnemonic).then(seed =>{
  // console.log(seed);
  var path = `m/44'/60'/0'/0/0`;
  var hdwallet = hdkey.fromMasterSeed(seed);
  var wallet = hdwallet.derivePath(path).getWallet();
  var address2 = "0x" + wallet.getAddress().toString("hex");
  var privateKey = wallet.getPrivateKey().toString("hex");
  console.log(`ethereumjs-wallet address: ${address2}`);
});

enter image description here

5
  • It returns different addresses: EthHdWallet Address: 0x206d287c87344e43ac7714aa88159213a31ddc7e ethereumjs-wallet address: 0x706458b3979ad760ea108f4040e4cdadf3985d75
    – Rudrika
    Jan 30, 2020 at 6:53
  • Are you using this code exactly? I'm posting the output I'm getting.
    – Steven V
    Jan 30, 2020 at 11:26
  • Yes same code! You've posted
    – Rudrika
    Jan 30, 2020 at 12:05
  • 1
    My Bad... Now get the exact addresses. I have changed m/44'/60'/0'/0/0 to "m/44'/60'/0'/0/0" may be that effected!
    – Rudrika
    Jan 30, 2020 at 12:51
  • Haha ok phew - I couldn’t imagine what was going on
    – Steven V
    Jan 30, 2020 at 13:04

Your Answer

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

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