-
Notifications
You must be signed in to change notification settings - Fork 0
/
mnemonic_to_key.js
27 lines (24 loc) · 1.03 KB
/
mnemonic_to_key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const bip39 = require("bip39");
const { hdkey } = require('ethereumjs-wallet');
const fs = require('fs');
function generateAddressesFromSeed(mnemonic, count) {
let seed = bip39.mnemonicToSeedSync(mnemonic);
let hdwallet = hdkey.fromMasterSeed(seed);
let wallet_hdpath = "m/44'/60'/0'/0/";
let accounts = [];
for (let index = 0; index < count; index++) {
let wallet = hdwallet.derivePath(wallet_hdpath + index).getWallet();
let address = "0x" + wallet.getAddress().toString("hex");
let privateKey = wallet.getPrivateKey().toString("hex");
console.log(`第${index}个地址已生成`)
accounts.push({ id: index + 1, address: address, privateKey: privateKey });
}
return accounts;
}
const mnemonic = "shine burst weather fish around library basic labor guilt pet valve web"
const count = 100;
const result = generateAddressesFromSeed(mnemonic, count);
fs.writeFile('keys.json', JSON.stringify(result), function (err) {
if (err) return console.log(err);
console.log(`地址生成完毕`);
});