使用Node批量创建ETH钱包

使用Node批量创建ETH钱包

安装Node

Download | Node.js

初始化项目

1
2
3
mkdir ETHWalletGenerator
cd ETHWalletGenerator
npm init

配置ETH相关的环境

1
2
npm install secp256k1
npm install keccak

创建并且编辑ethGenerator.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
28
29
30
31
32
33
'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);
}

批量生成

1
node ethGenerator.js
0%