Created
December 22, 2021 00:17
-
-
Save antojoseph/ffdd8cd699c42b213861ddd57665f067 to your computer and use it in GitHub Desktop.
Ethereum HD wallet example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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