1

I've been unable to generate the Account I see in MetaMask in EthereumJSWallet even if I use the same mnemonic.

Due to the lack of documentation, I may be misunderstanding how to do so. I have run the following 2 code-blocks in a Truffle Node console in my Terminal but I never got the correct result.

The variable mnemonic holds my MetaMask 12 word string. Per the HD Wallet API section of the EthereumJSWallet docs, I should "use bip39 to create [a seed] from a BIP39 mnemonic." However, I'm still unable to generate the appropriate account.

Neither wallet_test nor any of the derived paths in either of the 2 code-snippets below correspond to my first account.

Attempt 1:

var seed = bip39.mnemonicToSeed(mnemonic)
var wallet_test = hdkey.fromMasterSeed(seed)
wallet_test.derivePath("m/44'/60'/0'/0/0")
wallet_test.derivePath("m/44'/60'/0'/0")

Attempt 2:

var seed = bip39.mnemonicToSeedHex(mnemonic)
var wallet_test = hdkey.fromMasterSeed(seed)
wallet_test.derivePath("m/44'/60'/0'/0/0")
wallet_test.derivePath("m/44'/60'/0'/0")

Any help please?

2

This code will generate the same address from the mnemonic that MetaMask, MyEtherWallet, etc

const bip39 = require('bip39');
const hdkey = require('ethereumjs-wallet/hdkey');

const mnemonic = 'party box feel talent peace tiger endorse defy cheese girl tumble mail';
const seed = bip39.mnemonicToSeed(mnemonic);

const hdwallet = hdkey.fromMasterSeed(seed);
const myWallet = hdwallet.derivePath("m/44'/60'/0'/0/0").getWallet();

console.log(`Address: ${myWallet.getAddressString()}`);
console.log(`Private Key: ${myWallet.getPrivateKeyString()}`);

It doesn't add the checksum to the address

  • 0x999c43b9dd689b9a0bf12ce097663857f62ffbe7 without checksum
  • 0x999C43B9DD689b9a0bF12Ce097663857f62ffbe7 with checksum
  • how to use same code in flutter, – Ishwar Chandra Mar 26 at 16:24
  • @IshwarChandraTiwari Sorry, but I've never used flutter. It is better if you ask a a new question about that. – Ismael Mar 26 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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