Ethereumjs – Different Address with Single Mnemonic Phrase

ethereumjshd-wallets

I'm trying to implement ethereumjs-wallet library to my code.
But when I decided to compare generated accounts with accounts generated with the same mnemonic here, I got absolutely different accounts, even when seed was identical to mine. What am I missing?

I do it like this:

Web3 = require('web3');
bip39 = require('bip39')
etherHDkey = require('ethereumjs-wallet/hdkey')
ethUtil = require('ethereumjs-util')

mnemonic = bip39.generateMnemonic()
seedHex = bip39.mnemonicToSeedHex(mnemonic)
HDwallet = etherHDkey.fromMasterSeed(seedHex)
zeroWallet = HDwallet.derivePath("m/44'/60'/0'/0/0").getWallet();
console.log(mnemonic)
console.log(seedHex)
console.log(`Address: ${zeroWallet.getAddressString()}`);
console.log(`Private Key: ${zeroWallet.getPrivateKeyString()}`);

And here is the output:

slogan east ugly dish enable remove economy faint senior pause mention where
db90f73b1f23d449b021739c6c3aa85e47e8e26aa95b1ff6e883773536e6b126e15c34876070bd37befead1fc74057dfce2c6b045e8d4de6146584c96940486f
Address: 0xf298302699395cb4472b74e41427733c0ce6bcff
Private Key: 0x5b1b539ca7edd8e78f2c33fc6d9f1ef0d35db3490de9ed04f92c20bde54fbf48

Then when I insert this mnemonic slogan east ugly dish enable remove economy faint senior pause mention where to corresponding field here, I get the same seed BUT absolutely different addresses.

e.g. I get 0x7C373bAD5cF89b5c2730486eF2c1b8E803eD11d5 from m/44'/60'/0'/0/0' instead of expected 0xf298302699395cb4472b74e41427733c0ce6bcff using the same path m/44'/60'/0'/0/0'

What could be wrong here? Thank you.

Best Answer

Your problem resides on lines 7 and 8 where you are feeding the seed hex into the fromMasterSeed function. What you should be doing is feeding the raw seed in. When you do so, you end up with identical output as freewallet.org:

Web3 = require('web3');
bip39 = require('bip39')
etherHDkey = require('ethereumjs-wallet/hdkey')
ethUtil = require('ethereumjs-util')

mnemonic = bip39.generateMnemonic()
seed = bip39.mnemonicToSeed(mnemonic)
HDwallet = etherHDkey.fromMasterSeed(seed)
zeroWallet = HDwallet.derivePath("m/44'/60'/0'/0/0").getWallet();
console.log(mnemonic)
console.log(seed)
console.log(`Address: ${zeroWallet.getAddressString()}`);
console.log(`Private Key: ${zeroWallet.getPrivateKeyString()}`);

Output:

soldier mechanic sleep gym extend bone bundle price exhaust solar attack whale
<Buffer f0 80 57 49 3c 24 2c 4d 93 d6 c7 77 26 a7 40 37 8b 79 ed 83 8d 61 fb 57 36 43 44 41 69 bb 57 a8 46 21 71 b5 93 de ea 9c 4b 0c ea dd 70 81 cb 8c 8a 33 ... >
Address: 0x666e89cef3d251774f17e82c5a98e3622dd82dd8
Private Key: 0xf0e65787415522d260fce50ddfff4c4506714d58ee39f9a548b0102fa1d3be69

Which matches with freewallet.org's output identically.

Related Topic