Addresses

如果使用 EthHDWallet 生成錢包和地址,我們可以通過提供種子使用 ethereumjs-utils/hdkey getWallet() 方法來恢復它嗎?

  • January 30, 2020

生成的錢包地址使用:

let mnemonic = request.body.seed;
const wallet = EthHdWallet.fromMnemonic(mnemonic);
let address = wallet.generateAddresses(1);
console.log(wallet, address);

如何使用 恢復錢包地址mnemonic

是 - 除了使用ethereumjs-walletnot ethereumjs-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}`);
});

在此處輸入圖像描述

引用自:https://ethereum.stackexchange.com/questions/79396