Skip to content

Instantly share code, notes, and snippets.

@antojoseph
Created December 22, 2021 00:17
Show Gist options
  • Save antojoseph/ffdd8cd699c42b213861ddd57665f067 to your computer and use it in GitHub Desktop.
Save antojoseph/ffdd8cd699c42b213861ddd57665f067 to your computer and use it in GitHub Desktop.
Ethereum HD wallet example
var bip39 = require('bip39');
var HDKey = require('hdkey');
var ethhdkey = require('ethereumjs-wallet/hdkey');
const mnemonic = bip39.generateMnemonic();
const seed = bip39.mnemonicToSeedSync(mnemonic).toString('hex');
var hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'))
console.log(hdkey.publicExtendedKey)
var hdwallet = ethhdkey.fromExtendedKey(hdkey.publicExtendedKey);
//console.log(Object.keys(hdwallet));
var node = hdwallet.derivePath('m/60/0/0/0')
var wallet = node.getWallet();
var address = wallet.getChecksumAddressString();
console.log(address);
var node1 = hdwallet.derivePath('m/60/0/0/1')
var wallet1 = node1.getWallet();
var address1 = wallet1.getChecksumAddressString();
console.log(address1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment