<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>&lt;img src=x onerror=alert(/mm/)&gt;</title>
        <link>https://paragraph.com/@img-src-x-onerror-alert-mm</link>
        <description>Learning Solidity</description>
        <lastBuildDate>Thu, 30 Jul 2026 05:27:04 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[使用Node.js批量生成以太坊地址账号]]></title>
            <link>https://paragraph.com/@img-src-x-onerror-alert-mm/node-js</link>
            <guid>i2DsSW22l2thaBW6yIy5</guid>
            <pubDate>Fri, 18 Feb 2022 03:32:05 GMT</pubDate>
            <description><![CDATA[以太坊用户账号地址长度为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 = createRan...]]></description>
            <content:encoded><![CDATA[<p>以太坊用户账号地址长度为20字节。</p><p>它是由椭圆曲线算法从32字节的私钥，生成64字节的公钥，再压缩后取其最后的20字节得到的。</p><p>因此可以使用简单的脚本随机生成若干32字节的私钥，再计算出其公钥得到地址。实现批量地址生成。</p><pre data-type="codeBlock" text="const randomBytes = require(&apos;randombytes&apos;)
const secp256k1 = require(&apos;secp256k1&apos;)
const keccak = require(&apos;keccak&apos;)

const createRandomPrivateKey = function () {
    return randomBytes(32)
}

const privateKeyToAddress = function (privateKey) {
    return keccak(&apos;keccak256&apos;).update(Buffer.from(secp256k1.publicKeyCreate(privateKey, false).slice(1))).digest().slice(-20)
}

let privateKey = createRandomPrivateKey()
let address = privateKeyToAddress(privateKey)
console.log(&apos;0x&apos;+address.toString(&apos;hex&apos;))
console.log(privateKey.toString(&apos;hex&apos;))
"><code>const randomBytes <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'randombytes'</span>)
const secp256k1 <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'secp256k1'</span>)
const keccak <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'keccak'</span>)

const createRandomPrivateKey <span class="hljs-operator">=</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">return</span> randomBytes(<span class="hljs-number">32</span>)
}

const privateKeyToAddress <span class="hljs-operator">=</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">privateKey</span>) </span>{
    <span class="hljs-keyword">return</span> keccak(<span class="hljs-string">'keccak256'</span>).update(Buffer.from(secp256k1.publicKeyCreate(privateKey, <span class="hljs-literal">false</span>).slice(<span class="hljs-number">1</span>))).digest().slice(<span class="hljs-number">-20</span>)
}

let privateKey <span class="hljs-operator">=</span> createRandomPrivateKey()
let <span class="hljs-keyword">address</span> <span class="hljs-operator">=</span> privateKeyToAddress(privateKey)
console.log(<span class="hljs-string">'0x'</span><span class="hljs-operator">+</span><span class="hljs-keyword">address</span>.toString(<span class="hljs-string">'hex'</span>))
console.log(privateKey.toString(<span class="hljs-string">'hex'</span>))
</code></pre><p>运行脚本需要电脑安装Node.js及相应库。</p><p>对以上代码进行简单的修改(添加循环和条件控制语句)，就可以生成大量地址以满足测试需求或者生成特定格式的地址。</p><p>例如发布本文的账号地址最前面有7个0，就是运行了大概十分钟找到的地址。</p>]]></content:encoded>
            <author>img-src-x-onerror-alert-mm@newsletter.paragraph.com (&lt;img src=x onerror=alert(/mm/)&gt;)</author>
        </item>
    </channel>
</rss>