Last active
June 6, 2022 07:13
-
-
Save AarenWang/0126066580eef9d1c765d2a08cf398fd to your computer and use it in GitHub Desktop.
generate bip39 hdwallet by nodejs
This file contains hidden or 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
/** | |
* npm init | |
* yarn add bip39 ethereum-hdwallet | |
*/ | |
const bip39 = require('bip39') | |
const HDWallet = require('ethereum-hdwallet') | |
//const mnemonic_chinese = bip39.generateMnemonic(128, null, bip39.wordlists.chinese_simplified) | |
//console.log("助记词:" + mnemonic_chinese) //生成中文助记词 | |
const mnemonic = bip39.generateMnemonic(128) | |
console.log("mnemonic:" + mnemonic) | |
console.log(" ") | |
async function getAddress(mnemonic) { | |
const seed = await bip39.mnemonicToSeed(mnemonic) //generate seed | |
const hdwallet = HDWallet.fromSeed(seed) | |
for (var i = 0; i < 10; i++) { | |
const key = hdwallet.derive(`m/44' /60' /0' /0/` + i) // loop variable | |
console.log("PublicKey = " + key.getPublicKey().toString('hex')) | |
console.log("PrivateKey = " + key.getPrivateKey().toString('hex')) | |
const EthAddress = '0x' + key.getAddress().toString('hex') | |
console.log("ETH Address = " + EthAddress) | |
console.log(" ") | |
} | |
} | |
getAddress(mnemonic) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment