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:Output:
Which matches with freewallet.org's output identically.