# 使用Node.js批量生成以太坊地址账号 **Published by:** [](https://paragraph.com/@img-src-x-onerror-alert-mm/) **Published on:** 2022-02-18 **URL:** https://paragraph.com/@img-src-x-onerror-alert-mm/node-js ## Content 以太坊用户账号地址长度为20字节。 它是由椭圆曲线算法从32字节的私钥,生成64字节的公钥,再压缩后取其最后的20字节得到的。 因此可以使用简单的脚本随机生成若干32字节的私钥,再计算出其公钥得到地址。实现批量地址生成。const randomBytes = require('randombytes') const secp256k1 = require('secp256k1') const keccak = require('keccak') const createRandomPrivateKey = function () { return randomBytes(32) } const privateKeyToAddress = function (privateKey) { return keccak('keccak256').update(Buffer.from(secp256k1.publicKeyCreate(privateKey, false).slice(1))).digest().slice(-20) } let privateKey = createRandomPrivateKey() let address = privateKeyToAddress(privateKey) console.log('0x'+address.toString('hex')) console.log(privateKey.toString('hex')) 运行脚本需要电脑安装Node.js及相应库。 对以上代码进行简单的修改(添加循环和条件控制语句),就可以生成大量地址以满足测试需求或者生成特定格式的地址。 例如发布本文的账号地址最前面有7个0,就是运行了大概十分钟找到的地址。 ## Publication Information - [](https://paragraph.com/@img-src-x-onerror-alert-mm/): Publication homepage - [All Posts](https://paragraph.com/@img-src-x-onerror-alert-mm/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@img-src-x-onerror-alert-mm): Subscribe to updates