Addresses
如果使用 EthHDWallet 生成錢包和地址,我們可以通過提供種子使用 ethereumjs-utils/hdkey getWallet() 方法來恢復它嗎?
生成的錢包地址使用:
let mnemonic = request.body.seed; const wallet = EthHdWallet.fromMnemonic(mnemonic); let address = wallet.generateAddresses(1); console.log(wallet, address);
如何使用 恢復錢包地址
mnemonic
?
是 - 除了使用
ethereumjs-wallet
notethereumjs-utils
。使用相同的助記符,其中任一支持 repo 在此處生成相同的帳戶地址:const { EthHdWallet } = require('eth-hd-wallet') var hdkey = require("ethereumjs-wallet/hdkey") var bip39 = require("bip39"); const mnemonic = bip39.generateMnemonic(); //generates string console.log(`mnemonic: ${mnemonic}`); const wallet = EthHdWallet.fromMnemonic(mnemonic); let address = wallet.generateAddresses(1); console.log(`EthHdWallet Address: ${address}`); bip39.mnemonicToSeed(mnemonic).then(seed =>{ // console.log(seed); var path = `m/44'/60'/0'/0/0`; var hdwallet = hdkey.fromMasterSeed(seed); var wallet = hdwallet.derivePath(path).getWallet(); var address2 = "0x" + wallet.getAddress().toString("hex"); var privateKey = wallet.getPrivateKey().toString("hex"); console.log(`ethereumjs-wallet address: ${address2}`); });