first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
0x3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1
|
||||
@@ -0,0 +1,23 @@
|
||||
import fs from 'fs/promises';
|
||||
|
||||
const filePath = './demoAccount.txt';
|
||||
|
||||
// 返回一个 Promise
|
||||
async function loadData() {
|
||||
try {
|
||||
const data = await fs.readFile(filePath, 'utf8');
|
||||
const privateKeyList = data.split('\n');
|
||||
return privateKeyList;
|
||||
} catch (err) {
|
||||
console.error('读取文件时发生错误:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 调用 loadData 并等待结果
|
||||
async function main() {
|
||||
const privateKeyList = await loadData();
|
||||
console.log(privateKeyList);
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,48 @@
|
||||
// generateWallet.mjs
|
||||
import { ethers } from "ethers";
|
||||
|
||||
async function generateWallets(mnemonic, numWallets) {
|
||||
const wallets = [];
|
||||
|
||||
// 验证助记词是否有效
|
||||
if (!ethers.Mnemonic.isValidMnemonic(mnemonic)) {
|
||||
throw new Error("Invalid mnemonic phrase");
|
||||
}
|
||||
|
||||
for (let i = 0; i < numWallets; i++) {
|
||||
// 使用 BIP-44 派生路径生成钱包
|
||||
const path = `m/44'/60'/0'/0/${i}`;
|
||||
// 显式创建 HD 节点并派生钱包
|
||||
const hdNode = ethers.HDNodeWallet.fromPhrase(mnemonic, undefined, path);
|
||||
const wallet = new ethers.Wallet(hdNode.privateKey);
|
||||
const address = wallet.address;
|
||||
const privateKey = wallet.privateKey;
|
||||
|
||||
wallets.push({ address, privateKey, mnemonic, path }); // 包含路径以便调试
|
||||
}
|
||||
|
||||
const addresses = new Set(wallets.map(w => w.address));
|
||||
if (addresses.size !== numWallets) {
|
||||
throw new Error(`Duplicate wallets detected! Generated ${addresses.size} unique addresses instead of ${numWallets}`);
|
||||
}
|
||||
|
||||
return wallets;
|
||||
}
|
||||
|
||||
const mnemonic = "need rare control glove luxury punch orbit beef antique return average appear trumpet cattle hundred unknown unable exist rotate village produce address guilt naive";
|
||||
const numWallets = 100;
|
||||
|
||||
generateWallets(mnemonic, numWallets)
|
||||
.then(wallets => {
|
||||
wallets.forEach((wallet, index) => {
|
||||
console.log(`Wallet ${index + 1}:`);
|
||||
console.log(` Address: ${wallet.address}`);
|
||||
console.log(` Private Key: ${wallet.privateKey}`);
|
||||
console.log(` Mnemonic: ${wallet.mnemonic}`);
|
||||
console.log(` Path: ${wallet.path}`);
|
||||
console.log("---");
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error generating wallets:", error.message);
|
||||
});
|
||||
Reference in New Issue
Block a user