使用Node批量创建ETH钱包
技术/BlockChain
安装Node
Download | Node.js
初始化项目
mkdir ETHWalletGenerator
cd ETHWalletGenerator
npm init
配置ETH相关的环境
npm install secp256k1
npm install keccak
创建并且编辑ethGenerator.js
'use strict';
console.log('Generator Start..............');
const num = 5;
const secp256k1 = require("secp256k1/elliptic");
const createKeccakHash = require("keccak");
const crypto = require('crypto');
function toChecksumAddress(address) {
address = address.toLowerCase().replace('0x', '');
var hash = createKeccakHash('keccak256').update(address).digest('hex');
var ret = '0x';
for (var i = 0; i < address.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += address[i].toUpperCase();
} else {
ret += address[i];
}
}
return ret;
}
for (var i = 0; i < num; i++) {
const privateKey = crypto.randomBytes(32);
const publicKey = secp256k1.publicKeyCreate(privateKey, false).slice(1);
const address = createKeccakHash("keccak256").update(publicKey).digest().slice(-20);
const normAddress = toChecksumAddress(address.toString('hex'));
console.log(privateKey.toString('hex'));
console.log(normAddress);
}
批量生成
node ethGenerator.js