1. 程式人生 > >以太坊HD錢包地址生成方式一

以太坊HD錢包地址生成方式一

使用nodeJs生成以太坊HD錢包地址

程式碼

var bip39 = require('bip39')
var hdkey = require('ethereumjs-wallet/hdkey')
var util = require('ethereumjs-util')

var mnemonic = bip39.generateMnemonic()
var seed = bip39.mnemonicToSeed(mnemonic)
var hdWallet = hdkey.fromMasterSeed(seed)
var key1 = hdWallet.derivePath("m/44'/60'/0'/0/0")
console.log(key1)
var address1 = util.pubToAddress(key1._hdkey._publicKey, true)
console.log(address1)
address1 = util.toChecksumAddress(address1.toString('hex'))
console.log(address1)

效果截圖
這裡寫圖片描述