<?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>Runker54</title>
        <link>https://paragraph.com/@runker54</link>
        <description>Solidity,JS,Python</description>
        <lastBuildDate>Mon, 11 May 2026 22:12:29 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>Runker54</title>
            <url>https://storage.googleapis.com/papyrus_images/d760ffa8ecabbc2d4cb026f75fad39d8c8465b4f38f1c493c016bb83719f152f.png</url>
            <link>https://paragraph.com/@runker54</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[使用python在Base测试网络上批量为每个账户部署合约,领取你的NFT]]></title>
            <link>https://paragraph.com/@runker54/python-base-nft</link>
            <guid>58LB2Ia5WPZ3Ra66Dsa6</guid>
            <pubDate>Tue, 25 Apr 2023 16:14:24 GMT</pubDate>
            <description><![CDATA[我是一个刚学习智能合约的小白，最近coinbase的base测试网络现在部署一个合约可以免费mint一个nft,目前已mint了90多W个，感觉比较火，现在把我批量部署合约的方法分享给大家，使用语言为python。思路很简单，以ERC20代币为例，在openzeppelin上找到对应的ERC20标准库，写一个通用的ERC20代币的合约。为了让每个账户部署的合约都不相同（让编译的字节码不同），要让源码不同所以我们需要对应更改合约的名字就可以让每次合约部署后的字节码不同，然后在部署合约时随机生成该合约需要的三个传入参数（名字、符号、总供给），这样就实现了每个账户都创建了不同的合约。 具体过程： 1、通用的ERC20代币合约。 2、跨桥的脚本（从goerli到base）。 2、替换合约名字、编译合约内容、部署合约的脚本。 3、批量创建钱包脚本。 4、批量转账脚本。 5、批量mint脚本（由于这个NFTmint使用的是mintwithSignture方法mint目前还没找到需要怎么搞！！！替代方法可以用selenium代替。） 6、合约验证（如果需要让合约源码能让大家看到，就需要这一步。...]]></description>
            <content:encoded><![CDATA[<p>     我是一个刚学习智能合约的小白，最近coinbase的base测试网络现在部署一个合约可以免费mint一个nft,目前已mint了90多W个，感觉比较火，现在把我批量部署合约的方法分享给大家，使用语言为python。思路很简单，以ERC20代币为例，在openzeppelin上找到对应的ERC20标准库，写一个通用的ERC20代币的合约。为了让每个账户部署的合约都不相同（让编译的字节码不同），要让源码不同所以我们需要对应更改合约的名字就可以让每次合约部署后的字节码不同，然后在部署合约时随机生成该合约需要的三个传入参数（名字、符号、总供给），这样就实现了每个账户都创建了不同的合约。 具体过程： 1、通用的ERC20代币合约。 2、跨桥的脚本（从goerli到base）。 2、替换合约名字、编译合约内容、部署合约的脚本。 3、批量创建钱包脚本。 4、批量转账脚本。 5、批量mint脚本（由于这个NFTmint使用的是mintwithSignture方法mint目前还没找到需要怎么搞！！！替代方法可以用selenium代替。） 6、合约验证（如果需要让合约源码能让大家看到，就需要这一步。可以在hardhat上实现，因为这个合约部署时有三个参数，验证的时候也需要。所以我们在部署时就需要把他存储下来，以便后面使用hardhat批量验证合约。）</p><p>合约部署和使用hardhat验证的官方文档在这里</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.base.org/guides/deploy-smart-contracts">https://docs.base.org/guides/deploy-smart-contracts</a></p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">合约文件</h3><p>前面部分全是openzeppelin拷贝的，合约部署时需要传入代币名字、符号、以及要mint给部署者的代币数量。</p><pre data-type="codeBlock" text="//SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;

interface IERC20 {
    event Transfer(address indexed from, address indexed to, uint256 value);

    event Approval(
        address indexed owner,
        address indexed spender,
        uint256 value
    );

    function totalSupply() external view returns (uint256);

    function balanceOf(address account) external view returns (uint256);

    function transfer(address to, uint256 amount) external returns (bool);

    function allowance(
        address owner,
        address spender
    ) external view returns (uint256);

    function approve(address spender, uint256 amount) external returns (bool);

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

interface IERC20Metadata is IERC20 {
    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external view returns (uint8);
}

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address =&gt; uint256) private _balances;

    mapping(address =&gt; mapping(address =&gt; uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    function name() public view virtual override returns (string memory) {
        return _name;
    }

    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(
        address account
    ) public view virtual override returns (uint256) {
        return _balances[account];
    }

    function transfer(
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    function allowance(
        address owner,
        address spender
    ) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(
        address spender,
        uint256 amount
    ) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    function increaseAllowance(
        address spender,
        uint256 addedValue
    ) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    function decreaseAllowance(
        address spender,
        uint256 subtractedValue
    ) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(
            currentAllowance &gt;= subtractedValue,
            &quot;ERC20: decreased allowance below zero&quot;
        );
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), &quot;ERC20: transfer from the zero address&quot;);
        require(to != address(0), &quot;ERC20: transfer to the zero address&quot;);

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(
            fromBalance &gt;= amount,
            &quot;ERC20: transfer amount exceeds balance&quot;
        );
        unchecked {
            _balances[from] = fromBalance - amount;

            _balances[to] += amount;
        }
        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), &quot;ERC20: mint to the zero address&quot;);

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), &quot;ERC20: burn from the zero address&quot;);

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance &gt;= amount, &quot;ERC20: burn amount exceeds balance&quot;);
        unchecked {
            _balances[account] = accountBalance - amount;
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), &quot;ERC20: approve from the zero address&quot;);
        require(spender != address(0), &quot;ERC20: approve to the zero address&quot;);

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(
                currentAllowance &gt;= amount,
                &quot;ERC20: insufficient allowance&quot;
            );
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

contract ErcToken is ERC20 {
   
    constructor(
        string memory name,
        string memory symbol,
        uint256 totalSupply
    ) ERC20(name, symbol) {
        _mint(msg.sender, totalSupply * (10 ** 18));
    }
}
"><code><span class="hljs-comment">//SPDX-License-Identifier:MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IERC20</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">event</span> <span class="hljs-title">Transfer</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> <span class="hljs-keyword">indexed</span> <span class="hljs-keyword">from</span>, <span class="hljs-keyword">address</span> <span class="hljs-keyword">indexed</span> to, <span class="hljs-keyword">uint256</span> value</span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">event</span> <span class="hljs-title">Approval</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">indexed</span> owner,
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">indexed</span> spender,
        <span class="hljs-keyword">uint256</span> value
    </span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">totalSupply</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> account</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> to, <span class="hljs-keyword">uint256</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">allowance</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> owner,
        <span class="hljs-keyword">address</span> spender
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">approve</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> spender, <span class="hljs-keyword">uint256</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transferFrom</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span>,
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>)</span>;
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IERC20Metadata</span> <span class="hljs-keyword">is</span> <span class="hljs-title">IERC20</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">name</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">symbol</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span></span>)</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">decimals</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint8</span></span>)</span>;
}

<span class="hljs-keyword">abstract</span> <span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Context</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_msgSender</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">address</span></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_msgData</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">data</span>;
    }
}

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">ERC20</span> <span class="hljs-keyword">is</span> <span class="hljs-title">Context</span>, <span class="hljs-title">IERC20</span>, <span class="hljs-title">IERC20Metadata</span> </span>{
    <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">address</span> <span class="hljs-operator">=</span><span class="hljs-operator">></span> <span class="hljs-keyword">uint256</span>) <span class="hljs-keyword">private</span> _balances;

    <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">address</span> <span class="hljs-operator">=</span><span class="hljs-operator">></span> <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">address</span> <span class="hljs-operator">=</span><span class="hljs-operator">></span> <span class="hljs-keyword">uint256</span>)) <span class="hljs-keyword">private</span> _allowances;

    <span class="hljs-keyword">uint256</span> <span class="hljs-keyword">private</span> _totalSupply;

    <span class="hljs-keyword">string</span> <span class="hljs-keyword">private</span> _name;
    <span class="hljs-keyword">string</span> <span class="hljs-keyword">private</span> _symbol;

    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> name_, <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> symbol_</span>) </span>{
        _name <span class="hljs-operator">=</span> name_;
        _symbol <span class="hljs-operator">=</span> symbol_;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">name</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span></span>) </span>{
        <span class="hljs-keyword">return</span> _name;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">symbol</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span></span>) </span>{
        <span class="hljs-keyword">return</span> _symbol;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">decimals</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint8</span></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-number">18</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">totalSupply</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>) </span>{
        <span class="hljs-keyword">return</span> _totalSupply;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> account
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>) </span>{
        <span class="hljs-keyword">return</span> _balances[account];
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>) </span>{
        <span class="hljs-keyword">address</span> owner <span class="hljs-operator">=</span> _msgSender();
        _transfer(owner, to, amount);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">allowance</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> owner,
        <span class="hljs-keyword">address</span> spender
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>) </span>{
        <span class="hljs-keyword">return</span> _allowances[owner][spender];
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">approve</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> spender,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>) </span>{
        <span class="hljs-keyword">address</span> owner <span class="hljs-operator">=</span> _msgSender();
        _approve(owner, spender, amount);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transferFrom</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span>,
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">override</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>) </span>{
        <span class="hljs-keyword">address</span> spender <span class="hljs-operator">=</span> _msgSender();
        _spendAllowance(<span class="hljs-keyword">from</span>, spender, amount);
        _transfer(<span class="hljs-keyword">from</span>, to, amount);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">increaseAllowance</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> spender,
        <span class="hljs-keyword">uint256</span> addedValue
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>) </span>{
        <span class="hljs-keyword">address</span> owner <span class="hljs-operator">=</span> _msgSender();
        _approve(owner, spender, allowance(owner, spender) <span class="hljs-operator">+</span> addedValue);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">decreaseAllowance</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> spender,
        <span class="hljs-keyword">uint256</span> subtractedValue
    </span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>) </span>{
        <span class="hljs-keyword">address</span> owner <span class="hljs-operator">=</span> _msgSender();
        <span class="hljs-keyword">uint256</span> currentAllowance <span class="hljs-operator">=</span> allowance(owner, spender);
        <span class="hljs-built_in">require</span>(
            currentAllowance <span class="hljs-operator">></span><span class="hljs-operator">=</span> subtractedValue,
            <span class="hljs-string">"ERC20: decreased allowance below zero"</span>
        );
        <span class="hljs-keyword">unchecked</span> {
            _approve(owner, spender, currentAllowance <span class="hljs-operator">-</span> subtractedValue);
        }

        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_transfer</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span>,
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{
        <span class="hljs-built_in">require</span>(<span class="hljs-keyword">from</span> <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: transfer from the zero address"</span>);
        <span class="hljs-built_in">require</span>(to <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: transfer to the zero address"</span>);

        _beforeTokenTransfer(<span class="hljs-keyword">from</span>, to, amount);

        <span class="hljs-keyword">uint256</span> fromBalance <span class="hljs-operator">=</span> _balances[<span class="hljs-keyword">from</span>];
        <span class="hljs-built_in">require</span>(
            fromBalance <span class="hljs-operator">></span><span class="hljs-operator">=</span> amount,
            <span class="hljs-string">"ERC20: transfer amount exceeds balance"</span>
        );
        <span class="hljs-keyword">unchecked</span> {
            _balances[<span class="hljs-keyword">from</span>] <span class="hljs-operator">=</span> fromBalance <span class="hljs-operator">-</span> amount;

            _balances[to] <span class="hljs-operator">+</span><span class="hljs-operator">=</span> amount;
        }
        <span class="hljs-keyword">emit</span> Transfer(<span class="hljs-keyword">from</span>, to, amount);

        _afterTokenTransfer(<span class="hljs-keyword">from</span>, to, amount);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_mint</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> account, <span class="hljs-keyword">uint256</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{
        <span class="hljs-built_in">require</span>(account <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: mint to the zero address"</span>);

        _beforeTokenTransfer(<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), account, amount);

        _totalSupply <span class="hljs-operator">+</span><span class="hljs-operator">=</span> amount;
        <span class="hljs-keyword">unchecked</span> {
            _balances[account] <span class="hljs-operator">+</span><span class="hljs-operator">=</span> amount;
        }
        <span class="hljs-keyword">emit</span> Transfer(<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), account, amount);

        _afterTokenTransfer(<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), account, amount);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_burn</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> account, <span class="hljs-keyword">uint256</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{
        <span class="hljs-built_in">require</span>(account <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: burn from the zero address"</span>);

        _beforeTokenTransfer(account, <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), amount);

        <span class="hljs-keyword">uint256</span> accountBalance <span class="hljs-operator">=</span> _balances[account];
        <span class="hljs-built_in">require</span>(accountBalance <span class="hljs-operator">></span><span class="hljs-operator">=</span> amount, <span class="hljs-string">"ERC20: burn amount exceeds balance"</span>);
        <span class="hljs-keyword">unchecked</span> {
            _balances[account] <span class="hljs-operator">=</span> accountBalance <span class="hljs-operator">-</span> amount;
            _totalSupply <span class="hljs-operator">-</span><span class="hljs-operator">=</span> amount;
        }

        <span class="hljs-keyword">emit</span> Transfer(account, <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), amount);

        _afterTokenTransfer(account, <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), amount);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_approve</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> owner,
        <span class="hljs-keyword">address</span> spender,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{
        <span class="hljs-built_in">require</span>(owner <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: approve from the zero address"</span>);
        <span class="hljs-built_in">require</span>(spender <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-string">"ERC20: approve to the zero address"</span>);

        _allowances[owner][spender] <span class="hljs-operator">=</span> amount;
        <span class="hljs-keyword">emit</span> Approval(owner, spender, amount);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_spendAllowance</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> owner,
        <span class="hljs-keyword">address</span> spender,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{
        <span class="hljs-keyword">uint256</span> currentAllowance <span class="hljs-operator">=</span> allowance(owner, spender);
        <span class="hljs-keyword">if</span> (currentAllowance <span class="hljs-operator">!</span><span class="hljs-operator">=</span> <span class="hljs-keyword">type</span>(<span class="hljs-keyword">uint256</span>).<span class="hljs-built_in">max</span>) {
            <span class="hljs-built_in">require</span>(
                currentAllowance <span class="hljs-operator">></span><span class="hljs-operator">=</span> amount,
                <span class="hljs-string">"ERC20: insufficient allowance"</span>
            );
            <span class="hljs-keyword">unchecked</span> {
                _approve(owner, spender, currentAllowance <span class="hljs-operator">-</span> amount);
            }
        }
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_beforeTokenTransfer</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span>,
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{}

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_afterTokenTransfer</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span>,
        <span class="hljs-keyword">address</span> to,
        <span class="hljs-keyword">uint256</span> amount
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">virtual</span></span> </span>{}
}

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">ErcToken</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC20</span> </span>{
   
    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params">
        <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> name,
        <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> symbol,
        <span class="hljs-keyword">uint256</span> totalSupply
    </span>) <span class="hljs-title">ERC20</span>(<span class="hljs-params">name, symbol</span>) </span>{
        _mint(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, totalSupply <span class="hljs-operator">*</span> (<span class="hljs-number">10</span> <span class="hljs-operator">*</span><span class="hljs-operator">*</span> <span class="hljs-number">18</span>));
    }
}
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">跨桥代码</h3><p>从goerli到base</p><pre data-type="codeBlock" text="from web3 import Web3
from web3.middleware import geth_poa_middleware
# goerli rpc 替换为自己的或者公用的
goerli_rpc = &quot;xxxxx&quot;
# goerli_rpc = &quot;https://mainnet.infura.io/v3/&quot;
w3_goerli = Web3(Web3.HTTPProvider(goerli_rpc))
w3_goerli.middleware_onion.inject(geth_poa_middleware, layer=0)
# bridge contract
# 跨桥合约地址
bridge_contract_address = Web3.to_checksum_address(&quot;0xe93c8cD0D409341205A592f8c4Ac1A5fe5585cfA&quot;)
# 跨桥合约用到的ABI
bridge_abi = [{&quot;inputs&quot;: [{&quot;internalType&quot;: &quot;address&quot;, &quot;name&quot;: &quot;_to&quot;, &quot;type&quot;: &quot;address&quot;}, {&quot;internalType&quot;: &quot;uint256&quot;, &quot;name&quot;: &quot;_value&quot;, &quot;type&quot;: &quot;uint256&quot;},
                          {&quot;internalType&quot;: &quot;uint64&quot;, &quot;name&quot;: &quot;_gasLimit&quot;, &quot;type&quot;: &quot;uint64&quot;}, {&quot;internalType&quot;: &quot;bool&quot;, &quot;name&quot;: &quot;_isCreation&quot;, &quot;type&quot;: &quot;bool&quot;},
                          {&quot;internalType&quot;: &quot;bytes&quot;, &quot;name&quot;: &quot;_data&quot;, &quot;type&quot;: &quot;bytes&quot;}], &quot;name&quot;: &quot;depositTransaction&quot;, &quot;outputs&quot;: [], &quot;stateMutability&quot;: &quot;payable&quot;, &quot;type&quot;: &quot;function&quot;}]
# 构建跨桥合约对象
bridge_contract = w3_goerli.eth.contract(address=bridge_contract_address, abi=bridge_abi)
# 实现跨桥的函数，传入账户私钥和跨桥金额即可。
def goerli_base_bridge(private_key, amount):
    account = w3_goerli.eth.account.from_key(private_key)
    tx_data = {&quot;from&quot;: account.address, &quot;nonce&quot;: w3_goerli.eth.get_transaction_count(account.address), &quot;value&quot;: Web3.to_wei(amount, &quot;ether&quot;)}
    tx = bridge_contract.functions.depositTransaction(account.address, Web3.to_wei(amount, &quot;ether&quot;), 100000, False, b&apos;&apos;).build_transaction(tx_data)
    signed_tx = account.sign_transaction(tx)
    tx_hash = w3_goerli.eth.send_raw_transaction(signed_tx.rawTransaction)
    tx_receipt = w3_goerli.eth.wait_for_transaction_receipt(tx_hash)
    return tx_hash.hex()

# ex: 跨桥1个ETH
goerli_base_bridge(&quot;你的私钥&quot;,1)
"><code>from web3 import Web3
from web3.middleware import geth_poa_middleware
<span class="hljs-comment"># goerli rpc 替换为自己的或者公用的</span>
<span class="hljs-attr">goerli_rpc</span> = <span class="hljs-string">"xxxxx"</span>
<span class="hljs-comment"># goerli_rpc = "https://mainnet.infura.io/v3/"</span>
<span class="hljs-attr">w3_goerli</span> = Web3(Web3.HTTPProvider(goerli_rpc))
w3_goerli.middleware_onion.inject(geth_poa_middleware, <span class="hljs-attr">layer</span>=<span class="hljs-number">0</span>)
<span class="hljs-comment"># bridge contract</span>
<span class="hljs-comment"># 跨桥合约地址</span>
<span class="hljs-attr">bridge_contract_address</span> = Web3.to_checksum_address(<span class="hljs-string">"0xe93c8cD0D409341205A592f8c4Ac1A5fe5585cfA"</span>)
<span class="hljs-comment"># 跨桥合约用到的ABI</span>
<span class="hljs-attr">bridge_abi</span> = [{<span class="hljs-string">"inputs"</span>: [{<span class="hljs-string">"internalType"</span>: <span class="hljs-string">"address"</span>, <span class="hljs-string">"name"</span>: <span class="hljs-string">"_to"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"address"</span>}, {<span class="hljs-string">"internalType"</span>: <span class="hljs-string">"uint256"</span>, <span class="hljs-string">"name"</span>: <span class="hljs-string">"_value"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"uint256"</span>},
                          {<span class="hljs-string">"internalType"</span>: <span class="hljs-string">"uint64"</span>, <span class="hljs-string">"name"</span>: <span class="hljs-string">"_gasLimit"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"uint64"</span>}, {<span class="hljs-string">"internalType"</span>: <span class="hljs-string">"bool"</span>, <span class="hljs-string">"name"</span>: <span class="hljs-string">"_isCreation"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"bool"</span>},
                          {<span class="hljs-string">"internalType"</span>: <span class="hljs-string">"bytes"</span>, <span class="hljs-string">"name"</span>: <span class="hljs-string">"_data"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"bytes"</span>}], <span class="hljs-string">"name"</span>: <span class="hljs-string">"depositTransaction"</span>, <span class="hljs-string">"outputs"</span>: [], <span class="hljs-string">"stateMutability"</span>: <span class="hljs-string">"payable"</span>, <span class="hljs-string">"type"</span>: <span class="hljs-string">"function"</span>}]
<span class="hljs-comment"># 构建跨桥合约对象</span>
<span class="hljs-attr">bridge_contract</span> = w3_goerli.eth.contract(address=bridge_contract_address, abi=bridge_abi)
<span class="hljs-comment"># 实现跨桥的函数，传入账户私钥和跨桥金额即可。</span>
def goerli_base_bridge(private_key, amount):
    <span class="hljs-attr">account</span> = w3_goerli.eth.account.from_key(private_key)
    <span class="hljs-attr">tx_data</span> = {<span class="hljs-string">"from"</span>: account.address, <span class="hljs-string">"nonce"</span>: w3_goerli.eth.get_transaction_count(account.address), <span class="hljs-string">"value"</span>: Web3.to_wei(amount, <span class="hljs-string">"ether"</span>)}
    <span class="hljs-attr">tx</span> = bridge_contract.functions.depositTransaction(account.address, Web3.to_wei(amount, <span class="hljs-string">"ether"</span>), <span class="hljs-number">100000</span>, <span class="hljs-literal">False</span>, b<span class="hljs-string">''</span>).build_transaction(tx_data)
    <span class="hljs-attr">signed_tx</span> = account.sign_transaction(tx)
    <span class="hljs-attr">tx_hash</span> = w3_goerli.eth.send_raw_transaction(signed_tx.rawTransaction)
    <span class="hljs-attr">tx_receipt</span> = w3_goerli.eth.wait_for_transaction_receipt(tx_hash)
    return tx_hash.hex()

<span class="hljs-comment"># ex: 跨桥1个ETH</span>
goerli_base_bridge("你的私钥",1)
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">批量创建账户</h3><pre data-type="codeBlock" text="from eth_account import Account
import eth_account.hdaccount as HDAccount
from web3 import Web3
import os
Account.enable_unaudited_hdwallet_features()  # 若需创建助记词需要执行此句
web3 = Web3(Web3.HTTPProvider(&quot;https://mainnet.infura.io/v3/&quot;))


def createAccount(numbers: int, Seed: bool):
    &quot;&quot;&quot;传入钱包数量和是否需要助记词&quot;&quot;&quot;
    if Seed:
        with open(&apos;wallets.txt&apos;, &apos;a+&apos;, encoding=&apos;utf-8&apos;) as f:
            for _ in range(numbers):
                mnemonic = HDAccount.generate_mnemonic(12, &apos;english&apos;)
                account = Account.from_mnemonic(mnemonic)
                address = account.address
                private_key = account.key.hex()
                f.write(f&quot;{address} {private_key} {mnemonic}\n&quot;)
    else:
        with open(&apos;wallets.txt&apos;, &apos;a+&apos;, encoding=&apos;utf-8&apos;) as f:
            for _ in range(numbers):
                account = Account.create()
                address = account.address
                private_key = account.key.hex()
                f.write(f&quot;{address} {private_key}\n&quot;)
    return


# ex:创建10000个无助记词钱包
createAccount(10000,False)  
# ex:创建10000个有助记词钱包
createAccount(10000,True)
"><code><span class="hljs-keyword">from</span> eth_account <span class="hljs-keyword">import</span> Account
<span class="hljs-keyword">import</span> eth_account.hdaccount <span class="hljs-keyword">as</span> HDAccount
<span class="hljs-keyword">from</span> web3 <span class="hljs-keyword">import</span> Web3
<span class="hljs-keyword">import</span> os
Account.enable_unaudited_hdwallet_features()  <span class="hljs-comment"># 若需创建助记词需要执行此句</span>
web3 = Web3(Web3.HTTPProvider(<span class="hljs-string">"https://mainnet.infura.io/v3/"</span>))


<span class="hljs-keyword">def</span> <span class="hljs-title function_">createAccount</span>(<span class="hljs-params">numbers: <span class="hljs-built_in">int</span>, Seed: <span class="hljs-built_in">bool</span></span>):
    <span class="hljs-string">"""传入钱包数量和是否需要助记词"""</span>
    <span class="hljs-keyword">if</span> Seed:
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">'wallets.txt'</span>, <span class="hljs-string">'a+'</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
            <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(numbers):
                mnemonic = HDAccount.generate_mnemonic(<span class="hljs-number">12</span>, <span class="hljs-string">'english'</span>)
                account = Account.from_mnemonic(mnemonic)
                address = account.address
                private_key = account.key.<span class="hljs-built_in">hex</span>()
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{address}</span> <span class="hljs-subst">{private_key}</span> <span class="hljs-subst">{mnemonic}</span>\n"</span>)
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">'wallets.txt'</span>, <span class="hljs-string">'a+'</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
            <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(numbers):
                account = Account.create()
                address = account.address
                private_key = account.key.<span class="hljs-built_in">hex</span>()
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{address}</span> <span class="hljs-subst">{private_key}</span>\n"</span>)
    <span class="hljs-keyword">return</span>


<span class="hljs-comment"># ex:创建10000个无助记词钱包</span>
createAccount(<span class="hljs-number">10000</span>,<span class="hljs-literal">False</span>)  
<span class="hljs-comment"># ex:创建10000个有助记词钱包</span>
createAccount(<span class="hljs-number">10000</span>,<span class="hljs-literal">True</span>)
</code></pre><h3 id="h-eth" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">批量发送ETH</h3><pre data-type="codeBlock" text="# coding:utf-8
import random
import string
from web3 import Web3
from web3.middleware import geth_poa_middleware

# goerli_rpc = &quot;https://rpc.ankr.com/eth_goerli&quot;
goerli_rpc = &quot;你的goerli网络rpc&quot;
w3_goerli = Web3(Web3.HTTPProvider(goerli_rpc))
w3_goerli.middleware_onion.inject(geth_poa_middleware, layer=0)
# base network rpc
base_rpc = &quot;https://goerli.base.org&quot;
w3 = Web3(Web3.HTTPProvider(base_rpc))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

# 从批量创建的账户文件中读取账户列表
def get_account_list(file):
    account_list = []
    with open(file, &quot;r&quot;, encoding=&apos;utf-8&apos;) as f:
        for line in f.readlines():
            temp_address = line.split(&quot; &quot;)[0]
            temp_private_key = line.split(&quot; &quot;)[1].strip()
            account_list.append([temp_address, temp_private_key])
    return account_list

# 在base网络上批量发送eth
def base_transfer_eth(send_account, receipt, amount):
    tx_params = {
        &quot;from&quot;: send_account.address,
        &quot;chainId&quot;: w3.eth.chain_id,
        &quot;to&quot;: Web3.to_checksum_address(receipt),
        &quot;value&quot;: Web3.to_wei(amount, &quot;ether&quot;),
        &quot;gas&quot;: 21000,
        &quot;gasPrice&quot;: w3.eth.gas_price,
        &quot;nonce&quot;: w3.eth.get_transaction_count(send_account.address),
    }
    # 签署交易并发送
    signed_txn = send_account.signTransaction(tx_params)
    txn_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
    wait_txn = w3.eth.wait_for_transaction_receipt(txn_hash)
    return txn_hash.hex()

# 在goerli网络上批量发送eth
def goerli_transfer_eth(send_account, receipt, amount):
    tx_params = {
        &quot;from&quot;: send_account.address,
        &quot;chainId&quot;: w3_goerli.eth.chain_id,
        &quot;to&quot;: Web3.to_checksum_address(receipt),
        &quot;value&quot;: Web3.to_wei(amount, &quot;ether&quot;),
        &quot;gas&quot;: 21000,
        &quot;gasPrice&quot;: w3_goerli.eth.gas_price,
        &quot;nonce&quot;: w3_goerli.eth.get_transaction_count(send_account.address),
    }
    # 签署交易并发送
    signed_txn = send_account.signTransaction(tx_params)
    txn_hash = w3_goerli.eth.send_raw_transaction(signed_txn.rawTransaction)
    wait_txn = w3_goerli.eth.wait_for_transaction_receipt(txn_hash)
    return txn_hash.hex()


if __name__ == &apos;__main__&apos;:
    send_key = &quot;你要发送ETH的账户的私钥&quot;
    send_account = w3.eth.account.from_key(send_key)
    # 获取需要接收ETH的账户列表
    account_list = get_account_list(&quot;wallets.txt&quot;)
    for account_data in account_list:
        account = w3.eth.account.from_key(account_data[1])
        print(f&quot;{account_data[0]} transfering...&quot;)
        try:
            # 示例在base网络上转账，如果要在goerli上换成对应的函数即可
            tx = base_transfer_eth(send_account, account.address, 0.001)
            # 记录转账成功账户
            with open(&quot;transfer_eth.txt&quot;, &quot;a+&quot;, encoding=&apos;utf-8&apos;) as f:
                f.write(f&quot;{account_data[0]} {tx}\n&quot;)
        except:
            # 记录转账失败的账户
            with open(&quot;transfer_eth.txt&quot;, &quot;a+&quot;, encoding=&apos;utf-8&apos;) as f:
                f.write(f&quot;{account_data[0]} {account_data[1]}\n&quot;)
        print(f&quot;{account_data[0]} transfered&quot;)
    print(&quot;done&quot;)
"><code><span class="hljs-comment"># coding:utf-8</span>
<span class="hljs-keyword">import</span> random
<span class="hljs-keyword">import</span> string
<span class="hljs-keyword">from</span> web3 <span class="hljs-keyword">import</span> Web3
<span class="hljs-keyword">from</span> web3.middleware <span class="hljs-keyword">import</span> geth_poa_middleware

<span class="hljs-comment"># goerli_rpc = "https://rpc.ankr.com/eth_goerli"</span>
goerli_rpc = <span class="hljs-string">"你的goerli网络rpc"</span>
w3_goerli = Web3(Web3.HTTPProvider(goerli_rpc))
w3_goerli.middleware_onion.inject(geth_poa_middleware, layer=<span class="hljs-number">0</span>)
<span class="hljs-comment"># base network rpc</span>
base_rpc = <span class="hljs-string">"https://goerli.base.org"</span>
w3 = Web3(Web3.HTTPProvider(base_rpc))
w3.middleware_onion.inject(geth_poa_middleware, layer=<span class="hljs-number">0</span>)

<span class="hljs-comment"># 从批量创建的账户文件中读取账户列表</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_account_list</span>(<span class="hljs-params">file</span>):
    account_list = []
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(file, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
        <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> f.readlines():
            temp_address = line.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">0</span>]
            temp_private_key = line.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">1</span>].strip()
            account_list.append([temp_address, temp_private_key])
    <span class="hljs-keyword">return</span> account_list

<span class="hljs-comment"># 在base网络上批量发送eth</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">base_transfer_eth</span>(<span class="hljs-params">send_account, receipt, amount</span>):
    tx_params = {
        <span class="hljs-string">"from"</span>: send_account.address,
        <span class="hljs-string">"chainId"</span>: w3.eth.chain_id,
        <span class="hljs-string">"to"</span>: Web3.to_checksum_address(receipt),
        <span class="hljs-string">"value"</span>: Web3.to_wei(amount, <span class="hljs-string">"ether"</span>),
        <span class="hljs-string">"gas"</span>: <span class="hljs-number">21000</span>,
        <span class="hljs-string">"gasPrice"</span>: w3.eth.gas_price,
        <span class="hljs-string">"nonce"</span>: w3.eth.get_transaction_count(send_account.address),
    }
    <span class="hljs-comment"># 签署交易并发送</span>
    signed_txn = send_account.signTransaction(tx_params)
    txn_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
    wait_txn = w3.eth.wait_for_transaction_receipt(txn_hash)
    <span class="hljs-keyword">return</span> txn_hash.<span class="hljs-built_in">hex</span>()

<span class="hljs-comment"># 在goerli网络上批量发送eth</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">goerli_transfer_eth</span>(<span class="hljs-params">send_account, receipt, amount</span>):
    tx_params = {
        <span class="hljs-string">"from"</span>: send_account.address,
        <span class="hljs-string">"chainId"</span>: w3_goerli.eth.chain_id,
        <span class="hljs-string">"to"</span>: Web3.to_checksum_address(receipt),
        <span class="hljs-string">"value"</span>: Web3.to_wei(amount, <span class="hljs-string">"ether"</span>),
        <span class="hljs-string">"gas"</span>: <span class="hljs-number">21000</span>,
        <span class="hljs-string">"gasPrice"</span>: w3_goerli.eth.gas_price,
        <span class="hljs-string">"nonce"</span>: w3_goerli.eth.get_transaction_count(send_account.address),
    }
    <span class="hljs-comment"># 签署交易并发送</span>
    signed_txn = send_account.signTransaction(tx_params)
    txn_hash = w3_goerli.eth.send_raw_transaction(signed_txn.rawTransaction)
    wait_txn = w3_goerli.eth.wait_for_transaction_receipt(txn_hash)
    <span class="hljs-keyword">return</span> txn_hash.<span class="hljs-built_in">hex</span>()


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    send_key = <span class="hljs-string">"你要发送ETH的账户的私钥"</span>
    send_account = w3.eth.account.from_key(send_key)
    <span class="hljs-comment"># 获取需要接收ETH的账户列表</span>
    account_list = get_account_list(<span class="hljs-string">"wallets.txt"</span>)
    <span class="hljs-keyword">for</span> account_data <span class="hljs-keyword">in</span> account_list:
        account = w3.eth.account.from_key(account_data[<span class="hljs-number">1</span>])
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> transfering..."</span>)
        <span class="hljs-keyword">try</span>:
            <span class="hljs-comment"># 示例在base网络上转账，如果要在goerli上换成对应的函数即可</span>
            tx = base_transfer_eth(send_account, account.address, <span class="hljs-number">0.001</span>)
            <span class="hljs-comment"># 记录转账成功账户</span>
            <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"transfer_eth.txt"</span>, <span class="hljs-string">"a+"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> <span class="hljs-subst">{tx}</span>\n"</span>)
        <span class="hljs-keyword">except</span>:
            <span class="hljs-comment"># 记录转账失败的账户</span>
            <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"transfer_eth.txt"</span>, <span class="hljs-string">"a+"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> <span class="hljs-subst">{account_data[<span class="hljs-number">1</span>]}</span>\n"</span>)
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> transfered"</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">"done"</span>)
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">随机生成合约名字-符号-总供给、替换合约内容、随机构造合约部署时传入的参数、编译合约</h3><p>使用python编译合约需要安装py-solc-x这个库，再随机生成合约名字的时候，为了让名字有含义，我们还需安装nltk这个库，它是一个常用的自然语言处理工具包，广泛应用于文本分析、语言模型等，他可以解决我们随机生成的合约名字有含义。</p><pre data-type="codeBlock" text="import nltk
import random
# 下载words集合（如果还没有下载的话）
nltk.download(&apos;words&apos;)

# 获取words集合中的所有单词
words_list = nltk.corpus.words.words()

# 从所有单词中随机选择一万个单词
def create_random_name():
    # 为了挑选出10000万个符合条件的词，我们需要扩大范围所以这里在100000个筛选出长度在3到8之间的单词
    random_words = [_ for _ in [random.choice(words_list) for _ in range(100000)] if (len(_) &gt; 3 and len(_) &lt; 9)]
    # 去重
    random_words = list(set(random_words))
    # 选出10000个单词
    result_words = [_ for _ in [random.choice(random_words) for _ in range(10000)] if (len(_) &gt; 3 and len(_) &lt; 9)]
    return result_words


# 替换sol文件中的合约名
def replace_contract_name(contranct_name_words_list):
    for one_words in contranct_name_words_list:
        # 保存合约名
        with open(&quot;Contract_name.txt&quot;, &quot;a+&quot;) as f:
            # 随机生成一个长度为0到2的随机数
            randons = len(one_words)-random.randint(0, 2)
            # 生成合约名，和一个基于合约名的symbol（长度随机减少了0,2） 写入文件，后面部署合约会用到
            f.write(f&quot;{str(one_words).capitalize()} {str(one_words[:randons]).upper()}\n&quot;)
        # 替换sol文件中的合约名
        with open(&quot;Token.sol&quot;, &quot;r&quot;) as f:
            # 读取文件内容
            contents = f.read()
            # 替换单词
            new_contents = contents.replace(&quot;需要替换为你通用合约文件中的合约名字（尽量唯一，以防替换到合约文件中其它的内容）&quot;, f&quot;{str(one_words).capitalize()}&quot;)
            # 打开新的sol文件并写入新内容./contractfile/是保存合约文件的文件夹，如果没有请自行创建和更改
            with open(f&quot;./contractfile/{str(one_words).capitalize()}.sol&quot;, &quot;w&quot;) as f:
                f.write(new_contents)

# 读取保存的随机名字的文件
def create_name_symbol():
    &quot;&quot;&quot;Create random name and symbol&quot;&quot;&quot;
    temp_list = []
    with open(&quot;Contract_name.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as f:
        name_list = f.readlines()
        for i in name_list:
            temp_list.append([i.split(&quot; &quot;)[0].strip(), i.split(&quot; &quot;)[1].strip()])
    return temp_list

# 随机给出代币的总供给
def create_total_supply():
    &quot;&quot;&quot;Create random data for contract&quot;&quot;&quot;
    total_supply_head = random.randint(1, 99)
    total_supply_tail = random.randint(6, 10)
    total_supply = total_supply_head * 10 ** total_supply_tail
    return total_supply

# 编译合约 传入使用的合约文件和合约名字，返回该合约的abi和字节码用于部署
def compile_sol_file(sol_file, contract_name):
    &quot;&quot;&quot;Compile solidity file&quot;&quot;&quot;
    with open(sol_file, &quot;r&quot;, encoding=&apos;utf-8&apos;) as file:
        source_code = file.read()
    compile_sol = compile_standard(
        {
            &quot;language&quot;: &quot;Solidity&quot;,
            &quot;sources&quot;: {f&quot;{contract_name}.sol&quot;: {&quot;content&quot;: source_code}},
            &quot;settings&quot;: {
                &quot;outputSelection&quot;: {&quot;*&quot;: {&quot;*&quot;: [&quot;abi&quot;, &quot;metadata&quot;, &quot;evm.bytecode&quot;, &quot;evm.sourceMap&quot;]}}
            }
        }
    )
    # get bytecode
    byte_code = compile_sol[&quot;contracts&quot;][f&quot;{contract_name}.sol&quot;][f&quot;{contract_name}&quot;][&quot;evm&quot;][&quot;bytecode&quot;][&quot;object&quot;]
    # get abi
    abi = compile_sol[&quot;contracts&quot;][f&quot;{contract_name}.sol&quot;][f&quot;{contract_name}&quot;][&quot;abi&quot;]
    return abi, byte_code
"><code><span class="hljs-keyword">import</span> nltk
<span class="hljs-keyword">import</span> random
<span class="hljs-comment"># 下载words集合（如果还没有下载的话）</span>
nltk.download(<span class="hljs-string">'words'</span>)

<span class="hljs-comment"># 获取words集合中的所有单词</span>
words_list = nltk.corpus.words.words()

<span class="hljs-comment"># 从所有单词中随机选择一万个单词</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_random_name</span>():
    <span class="hljs-comment"># 为了挑选出10000万个符合条件的词，我们需要扩大范围所以这里在100000个筛选出长度在3到8之间的单词</span>
    random_words = [_ <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> [random.choice(words_list) <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">100000</span>)] <span class="hljs-keyword">if</span> (<span class="hljs-built_in">len</span>(_) > <span class="hljs-number">3</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">len</span>(_) &#x3C; <span class="hljs-number">9</span>)]
    <span class="hljs-comment"># 去重</span>
    random_words = <span class="hljs-built_in">list</span>(<span class="hljs-built_in">set</span>(random_words))
    <span class="hljs-comment"># 选出10000个单词</span>
    result_words = [_ <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> [random.choice(random_words) <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">10000</span>)] <span class="hljs-keyword">if</span> (<span class="hljs-built_in">len</span>(_) > <span class="hljs-number">3</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">len</span>(_) &#x3C; <span class="hljs-number">9</span>)]
    <span class="hljs-keyword">return</span> result_words


<span class="hljs-comment"># 替换sol文件中的合约名</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">replace_contract_name</span>(<span class="hljs-params">contranct_name_words_list</span>):
    <span class="hljs-keyword">for</span> one_words <span class="hljs-keyword">in</span> contranct_name_words_list:
        <span class="hljs-comment"># 保存合约名</span>
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"Contract_name.txt"</span>, <span class="hljs-string">"a+"</span>) <span class="hljs-keyword">as</span> f:
            <span class="hljs-comment"># 随机生成一个长度为0到2的随机数</span>
            randons = <span class="hljs-built_in">len</span>(one_words)-random.randint(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>)
            <span class="hljs-comment"># 生成合约名，和一个基于合约名的symbol（长度随机减少了0,2） 写入文件，后面部署合约会用到</span>
            f.write(<span class="hljs-string">f"<span class="hljs-subst">{<span class="hljs-built_in">str</span>(one_words).capitalize()}</span> <span class="hljs-subst">{<span class="hljs-built_in">str</span>(one_words[:randons]).upper()}</span>\n"</span>)
        <span class="hljs-comment"># 替换sol文件中的合约名</span>
        <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"Token.sol"</span>, <span class="hljs-string">"r"</span>) <span class="hljs-keyword">as</span> f:
            <span class="hljs-comment"># 读取文件内容</span>
            contents = f.read()
            <span class="hljs-comment"># 替换单词</span>
            new_contents = contents.replace(<span class="hljs-string">"需要替换为你通用合约文件中的合约名字（尽量唯一，以防替换到合约文件中其它的内容）"</span>, <span class="hljs-string">f"<span class="hljs-subst">{<span class="hljs-built_in">str</span>(one_words).capitalize()}</span>"</span>)
            <span class="hljs-comment"># 打开新的sol文件并写入新内容./contractfile/是保存合约文件的文件夹，如果没有请自行创建和更改</span>
            <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">f"./contractfile/<span class="hljs-subst">{<span class="hljs-built_in">str</span>(one_words).capitalize()}</span>.sol"</span>, <span class="hljs-string">"w"</span>) <span class="hljs-keyword">as</span> f:
                f.write(new_contents)

<span class="hljs-comment"># 读取保存的随机名字的文件</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_name_symbol</span>():
    <span class="hljs-string">"""Create random name and symbol"""</span>
    temp_list = []
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"Contract_name.txt"</span>, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">"utf-8"</span>) <span class="hljs-keyword">as</span> f:
        name_list = f.readlines()
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> name_list:
            temp_list.append([i.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">0</span>].strip(), i.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">1</span>].strip()])
    <span class="hljs-keyword">return</span> temp_list

<span class="hljs-comment"># 随机给出代币的总供给</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_total_supply</span>():
    <span class="hljs-string">"""Create random data for contract"""</span>
    total_supply_head = random.randint(<span class="hljs-number">1</span>, <span class="hljs-number">99</span>)
    total_supply_tail = random.randint(<span class="hljs-number">6</span>, <span class="hljs-number">10</span>)
    total_supply = total_supply_head * <span class="hljs-number">10</span> ** total_supply_tail
    <span class="hljs-keyword">return</span> total_supply

<span class="hljs-comment"># 编译合约 传入使用的合约文件和合约名字，返回该合约的abi和字节码用于部署</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">compile_sol_file</span>(<span class="hljs-params">sol_file, contract_name</span>):
    <span class="hljs-string">"""Compile solidity file"""</span>
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(sol_file, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> file:
        source_code = file.read()
    compile_sol = compile_standard(
        {
            <span class="hljs-string">"language"</span>: <span class="hljs-string">"Solidity"</span>,
            <span class="hljs-string">"sources"</span>: {<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>: {<span class="hljs-string">"content"</span>: source_code}},
            <span class="hljs-string">"settings"</span>: {
                <span class="hljs-string">"outputSelection"</span>: {<span class="hljs-string">"*"</span>: {<span class="hljs-string">"*"</span>: [<span class="hljs-string">"abi"</span>, <span class="hljs-string">"metadata"</span>, <span class="hljs-string">"evm.bytecode"</span>, <span class="hljs-string">"evm.sourceMap"</span>]}}
            }
        }
    )
    <span class="hljs-comment"># get bytecode</span>
    byte_code = compile_sol[<span class="hljs-string">"contracts"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>"</span>][<span class="hljs-string">"evm"</span>][<span class="hljs-string">"bytecode"</span>][<span class="hljs-string">"object"</span>]
    <span class="hljs-comment"># get abi</span>
    abi = compile_sol[<span class="hljs-string">"contracts"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>"</span>][<span class="hljs-string">"abi"</span>]
    <span class="hljs-keyword">return</span> abi, byte_code
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">完整部署合约代码</h3><p>在做好账户创建、保证每个账户中有足够的ETH、合约名字、合约名字对应的sol文件这些准备工作后，就可以开始批量部署了。</p><pre data-type="codeBlock" text="# coding:utf-8
import random
import nltk
import string
from web3 import Web3
from web3.middleware import geth_poa_middleware
from solcx import compile_standard,install_solc
import time
# 确保安装了你想要的sol文件编译版本
install_solc(&quot;0.8.18&quot;)
# 确保下载了词库
nltk.download(&apos;words&apos;)
words_list = nltk.corpus.words.words()
# base RPC 公共的，如果有更快的你可以更换
base_rpc = &quot;https://goerli.base.org&quot;
w3 = Web3(Web3.HTTPProvider(base_rpc))
w3.middleware_onion.inject(geth_poa_middleware, layer=0)

# 编译合约
def compile_sol_file(sol_file, contract_name):
    &quot;&quot;&quot;Compile solidity file&quot;&quot;&quot;
    with open(sol_file, &quot;r&quot;, encoding=&apos;utf-8&apos;) as file:
        source_code = file.read()
    compile_sol = compile_standard(
        {
            &quot;language&quot;: &quot;Solidity&quot;,
            &quot;sources&quot;: {f&quot;{contract_name}.sol&quot;: {&quot;content&quot;: source_code}},
            &quot;settings&quot;: {
                &quot;outputSelection&quot;: {&quot;*&quot;: {&quot;*&quot;: [&quot;abi&quot;, &quot;metadata&quot;, &quot;evm.bytecode&quot;, &quot;evm.sourceMap&quot;]}}
            }
        }
    )
    # get bytecode
    byte_code = compile_sol[&quot;contracts&quot;][f&quot;{contract_name}.sol&quot;][f&quot;{contract_name}&quot;][&quot;evm&quot;][&quot;bytecode&quot;][&quot;object&quot;]
    # get abi
    abi = compile_sol[&quot;contracts&quot;][f&quot;{contract_name}.sol&quot;][f&quot;{contract_name}&quot;][&quot;abi&quot;]
    return abi, byte_code

# 获取随机合约名
def create_name_symbol():
    &quot;&quot;&quot;Create random name and symbol&quot;&quot;&quot;
    temp_list = []
    with open(&quot;Contract_name.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as f:
        name_list = f.readlines()
        for i in name_list:
            temp_list.append([i.split(&quot; &quot;)[0].strip(), i.split(&quot; &quot;)[1].strip()])
    return temp_list

# 创建随机供给
def create_total_supply():
    &quot;&quot;&quot;Create random data for contract&quot;&quot;&quot;
    total_supply_head = random.randint(1, 99)
    total_supply_tail = random.randint(6, 10)
    total_supply = total_supply_head * 10 ** total_supply_tail
    return total_supply

# 部署合约
def deploy_contract(private_key, abi, byte_code, _name, _symbol, _total_supply):
    &quot;&quot;&quot;Deploy contract&quot;&quot;&quot;
    account = w3.eth.account.from_key(private_key)
    # create contract
    contract = w3.eth.contract(abi=abi, bytecode=byte_code)
    # deploy contract
    tx_data = {&quot;from&quot;: account.address, &quot;nonce&quot;: w3.eth.get_transaction_count(account.address), &quot;gasPrice&quot;: w3.eth.gas_price}
    tx = contract.constructor(_name, _symbol, _total_supply).build_transaction(tx_data)
    signed_tx = account.sign_transaction(tx)
    tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
    tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
    # get contract address
    contract_address = tx_receipt.contractAddress
    return contract_address

def get_account_list(file):
    account_list = []
    with open(file, &quot;r&quot;, encoding=&apos;utf-8&apos;) as f:
        for line in f.readlines():
            temp_address = line.split(&quot; &quot;)[0]
            temp_private_key = line.split(&quot; &quot;)[1].strip()
            account_list.append([temp_address, temp_private_key])
    return account_list


if __name__ == &apos;__main__&apos;:
    # 获取要部署合约的用户列表
    account_list = get_account_list(&quot;wallets.txt&quot;)
    # 获取合约名字和符号的列表
    name_symbol_list = create_name_symbol()
    # 任务索引id
    index_i = 0
    # 循环每个账户进行部署合约
    for account_data in account_list:
        # 使用的合约名字
        name = name_symbol_list[index_i][0]
        # 使用的合约符号
        symbol = name_symbol_list[index_i][1]
        # 使用的总供给
        total_supply = create_total_supply()
        # 对应合约文件编译后的abi、字节码
        abi, byte_code = compile_sol_file(f&quot;./contractfile/{name}.sol&quot;, name)
        # 账户实例化
        account = w3.eth.account.from_key(account_data[1])
        print(f&quot;{account_data[0]} deploying...&quot;)
        try:
            # 开始部署
            tx = deploy_contract(account_data[1], abi, byte_code, name, symbol, total_supply)
            # 写入部署成功的信息，包含你部署的合约地址，后面mint会用到。
            with open(&quot;deploy.txt&quot;, &quot;a+&quot;, encoding=&apos;utf-8&apos;) as f:
                f.write(f&quot;{account_data[0]} {account_data[1]} {tx} {name} {symbol} {total_supply}\n&quot;)
        except Exception as e:
            # 打印报错信息
            print(e)
            # 写入部署失败的信息
            with open(&quot;deployfaild.txt&quot;, &quot;a+&quot;, encoding=&apos;utf-8&apos;) as f:
                f.write(f&quot;{account_data[0]} {account_data[1]}\n&quot;)
        print(f&quot;{account_data[0]} deployed&quot;)
        index_i += 1
"><code><span class="hljs-comment"># coding:utf-8</span>
<span class="hljs-keyword">import</span> random
<span class="hljs-keyword">import</span> nltk
<span class="hljs-keyword">import</span> string
<span class="hljs-keyword">from</span> web3 <span class="hljs-keyword">import</span> Web3
<span class="hljs-keyword">from</span> web3.middleware <span class="hljs-keyword">import</span> geth_poa_middleware
<span class="hljs-keyword">from</span> solcx <span class="hljs-keyword">import</span> compile_standard,install_solc
<span class="hljs-keyword">import</span> time
<span class="hljs-comment"># 确保安装了你想要的sol文件编译版本</span>
install_solc(<span class="hljs-string">"0.8.18"</span>)
<span class="hljs-comment"># 确保下载了词库</span>
nltk.download(<span class="hljs-string">'words'</span>)
words_list = nltk.corpus.words.words()
<span class="hljs-comment"># base RPC 公共的，如果有更快的你可以更换</span>
base_rpc = <span class="hljs-string">"https://goerli.base.org"</span>
w3 = Web3(Web3.HTTPProvider(base_rpc))
w3.middleware_onion.inject(geth_poa_middleware, layer=<span class="hljs-number">0</span>)

<span class="hljs-comment"># 编译合约</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">compile_sol_file</span>(<span class="hljs-params">sol_file, contract_name</span>):
    <span class="hljs-string">"""Compile solidity file"""</span>
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(sol_file, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> file:
        source_code = file.read()
    compile_sol = compile_standard(
        {
            <span class="hljs-string">"language"</span>: <span class="hljs-string">"Solidity"</span>,
            <span class="hljs-string">"sources"</span>: {<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>: {<span class="hljs-string">"content"</span>: source_code}},
            <span class="hljs-string">"settings"</span>: {
                <span class="hljs-string">"outputSelection"</span>: {<span class="hljs-string">"*"</span>: {<span class="hljs-string">"*"</span>: [<span class="hljs-string">"abi"</span>, <span class="hljs-string">"metadata"</span>, <span class="hljs-string">"evm.bytecode"</span>, <span class="hljs-string">"evm.sourceMap"</span>]}}
            }
        }
    )
    <span class="hljs-comment"># get bytecode</span>
    byte_code = compile_sol[<span class="hljs-string">"contracts"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>"</span>][<span class="hljs-string">"evm"</span>][<span class="hljs-string">"bytecode"</span>][<span class="hljs-string">"object"</span>]
    <span class="hljs-comment"># get abi</span>
    abi = compile_sol[<span class="hljs-string">"contracts"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>.sol"</span>][<span class="hljs-string">f"<span class="hljs-subst">{contract_name}</span>"</span>][<span class="hljs-string">"abi"</span>]
    <span class="hljs-keyword">return</span> abi, byte_code

<span class="hljs-comment"># 获取随机合约名</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_name_symbol</span>():
    <span class="hljs-string">"""Create random name and symbol"""</span>
    temp_list = []
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"Contract_name.txt"</span>, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">"utf-8"</span>) <span class="hljs-keyword">as</span> f:
        name_list = f.readlines()
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> name_list:
            temp_list.append([i.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">0</span>].strip(), i.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">1</span>].strip()])
    <span class="hljs-keyword">return</span> temp_list

<span class="hljs-comment"># 创建随机供给</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">create_total_supply</span>():
    <span class="hljs-string">"""Create random data for contract"""</span>
    total_supply_head = random.randint(<span class="hljs-number">1</span>, <span class="hljs-number">99</span>)
    total_supply_tail = random.randint(<span class="hljs-number">6</span>, <span class="hljs-number">10</span>)
    total_supply = total_supply_head * <span class="hljs-number">10</span> ** total_supply_tail
    <span class="hljs-keyword">return</span> total_supply

<span class="hljs-comment"># 部署合约</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">deploy_contract</span>(<span class="hljs-params">private_key, abi, byte_code, _name, _symbol, _total_supply</span>):
    <span class="hljs-string">"""Deploy contract"""</span>
    account = w3.eth.account.from_key(private_key)
    <span class="hljs-comment"># create contract</span>
    contract = w3.eth.contract(abi=abi, bytecode=byte_code)
    <span class="hljs-comment"># deploy contract</span>
    tx_data = {<span class="hljs-string">"from"</span>: account.address, <span class="hljs-string">"nonce"</span>: w3.eth.get_transaction_count(account.address), <span class="hljs-string">"gasPrice"</span>: w3.eth.gas_price}
    tx = contract.constructor(_name, _symbol, _total_supply).build_transaction(tx_data)
    signed_tx = account.sign_transaction(tx)
    tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
    tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
    <span class="hljs-comment"># get contract address</span>
    contract_address = tx_receipt.contractAddress
    <span class="hljs-keyword">return</span> contract_address

<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_account_list</span>(<span class="hljs-params">file</span>):
    account_list = []
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(file, <span class="hljs-string">"r"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
        <span class="hljs-keyword">for</span> line <span class="hljs-keyword">in</span> f.readlines():
            temp_address = line.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">0</span>]
            temp_private_key = line.split(<span class="hljs-string">" "</span>)[<span class="hljs-number">1</span>].strip()
            account_list.append([temp_address, temp_private_key])
    <span class="hljs-keyword">return</span> account_list


<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    <span class="hljs-comment"># 获取要部署合约的用户列表</span>
    account_list = get_account_list(<span class="hljs-string">"wallets.txt"</span>)
    <span class="hljs-comment"># 获取合约名字和符号的列表</span>
    name_symbol_list = create_name_symbol()
    <span class="hljs-comment"># 任务索引id</span>
    index_i = <span class="hljs-number">0</span>
    <span class="hljs-comment"># 循环每个账户进行部署合约</span>
    <span class="hljs-keyword">for</span> account_data <span class="hljs-keyword">in</span> account_list:
        <span class="hljs-comment"># 使用的合约名字</span>
        name = name_symbol_list[index_i][<span class="hljs-number">0</span>]
        <span class="hljs-comment"># 使用的合约符号</span>
        symbol = name_symbol_list[index_i][<span class="hljs-number">1</span>]
        <span class="hljs-comment"># 使用的总供给</span>
        total_supply = create_total_supply()
        <span class="hljs-comment"># 对应合约文件编译后的abi、字节码</span>
        abi, byte_code = compile_sol_file(<span class="hljs-string">f"./contractfile/<span class="hljs-subst">{name}</span>.sol"</span>, name)
        <span class="hljs-comment"># 账户实例化</span>
        account = w3.eth.account.from_key(account_data[<span class="hljs-number">1</span>])
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> deploying..."</span>)
        <span class="hljs-keyword">try</span>:
            <span class="hljs-comment"># 开始部署</span>
            tx = deploy_contract(account_data[<span class="hljs-number">1</span>], abi, byte_code, name, symbol, total_supply)
            <span class="hljs-comment"># 写入部署成功的信息，包含你部署的合约地址，后面mint会用到。</span>
            <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"deploy.txt"</span>, <span class="hljs-string">"a+"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> <span class="hljs-subst">{account_data[<span class="hljs-number">1</span>]}</span> <span class="hljs-subst">{tx}</span> <span class="hljs-subst">{name}</span> <span class="hljs-subst">{symbol}</span> <span class="hljs-subst">{total_supply}</span>\n"</span>)
        <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
            <span class="hljs-comment"># 打印报错信息</span>
            <span class="hljs-built_in">print</span>(e)
            <span class="hljs-comment"># 写入部署失败的信息</span>
            <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(<span class="hljs-string">"deployfaild.txt"</span>, <span class="hljs-string">"a+"</span>, encoding=<span class="hljs-string">'utf-8'</span>) <span class="hljs-keyword">as</span> f:
                f.write(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> <span class="hljs-subst">{account_data[<span class="hljs-number">1</span>]}</span>\n"</span>)
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f"<span class="hljs-subst">{account_data[<span class="hljs-number">0</span>]}</span> deployed"</span>)
        index_i += <span class="hljs-number">1</span>
</code></pre><p>合约部署完成以后你就可以使用你部署的合约地址去下面这个网址去mint你的NFT了。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://quests.base.org/">https://quests.base.org/</a></p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">合约验证</h3><p>合约验证使用hardhat来实现。不需要像主网、goerli和bsc验证合约需要api。你只需要按照官方的那个文档配置号你的config文件就可以了。</p><p>在你的hardhat.config.js中大概就像这样</p><pre data-type="codeBlock" text="require(&quot;@nomiclabs/hardhat-etherscan&quot;);
require(&quot;@nomicfoundation/hardhat-toolbox&quot;);
require(&quot;dotenv&quot;).config()
/** @type import(&apos;hardhat/config&apos;).HardhatUserConfig */
// 合约验证
module.exports = {
  solidity: {
    version: &quot;0.8.19&quot;,
  },
  etherscan: {
    apiKey: {
      // Basescan doesn&apos;t require an API key, however
      // Hardhat still expects an arbitrary string to be provided.
      &quot;basegoerli&quot;: &quot;PLACEHOLDER_STRING&quot;
    },
    customChains: [
      {
        network: &quot;basegoerli&quot;,
        chainId: 84531,
        urls: {
          apiURL: &quot;https://api-goerli.basescan.org/api&quot;,
          browserURL: &quot;https://goerli.basescan.org&quot;
        }
      }
    ]
  },
  networks: {
    basegoerli: {
      url: process.env.BASEGOERLI_URL,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};
"><code><span class="hljs-built_in">require</span>(<span class="hljs-string">"@nomiclabs/hardhat-etherscan"</span>);
<span class="hljs-built_in">require</span>(<span class="hljs-string">"@nomicfoundation/hardhat-toolbox"</span>);
<span class="hljs-built_in">require</span>(<span class="hljs-string">"dotenv"</span>).config()
<span class="hljs-comment">/** @type import('hardhat/config').HardhatUserConfig */</span>
<span class="hljs-comment">// 合约验证</span>
module.exports <span class="hljs-operator">=</span> {
  solidity: {
    version: <span class="hljs-string">"0.8.19"</span>,
  },
  etherscan: {
    apiKey: {
      <span class="hljs-comment">// Basescan doesn't require an API key, however</span>
      <span class="hljs-comment">// Hardhat still expects an arbitrary string to be provided.</span>
      <span class="hljs-string">"basegoerli"</span>: <span class="hljs-string">"PLACEHOLDER_STRING"</span>
    },
    customChains: [
      {
        network: <span class="hljs-string">"basegoerli"</span>,
        chainId: <span class="hljs-number">84531</span>,
        urls: {
          apiURL: <span class="hljs-string">"https://api-goerli.basescan.org/api"</span>,
          browserURL: <span class="hljs-string">"https://goerli.basescan.org"</span>
        }
      }
    ]
  },
  networks: {
    basegoerli: {
      url: process.env.BASEGOERLI_URL,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
};
</code></pre><p>1、把你部署好的合约文件拷贝一份到hardhat的contract文件夹下</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7c22c57fd2cb763027ab58e8dec6a7406c8d741a51592717c696c8d926144f95.png" alt="合约文件" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">合约文件</figcaption></figure><p>2、在命令行输入npx hardhat compile编译好这个合约文件，然后在scripts文件夹下编写验证合约的js脚本，我这里以两个为例我是这样写的。然后在命令行输入npx hardhat run scripts/（这个部署js的文件名.js）--network basegoerli(我给他去的名字是这个，你的要对应更改)</p><pre data-type="codeBlock" text="const hre = require(&quot;hardhat&quot;);

async function main() {
    const { ethers } = hre;

    //你对应的合约地址，多个的话可以写个函数读取
    const contractAddresses = [
        &quot;0x045d788952D4DA8aA1D0dEDc2fBe1dDeE387C018&quot;,
        // ...
    ];
    //你对应的合约部署时的参数，多个的话可以写个函数读取
    const constructorArgs = [
        [&quot;Gobelin&quot;, &quot;GOBELI&quot;, 1000000000],
        // ...
    ];

    for (let i = 0; i &lt; contractAddresses.length; i++) {
        const address = contractAddresses[i];
        const args = constructorArgs[i];
        console.log(`Verifying contract at ${address}...`);
        await hre.run(&quot;verify:verify&quot;, {
            address,
            constructorArguments: args,
            # 你的合约文件名和合约名，多个的话写成函数传参形式替换
            contract: &quot;Token.sol:Token&quot;,
            network: &quot;basegoerli&quot;,
        });
        console.log(`Contract at ${address} verified successfully.`);
    }
}

main()
    .then(() =&gt; process.exit(0))
    .catch(error =&gt; {
        console.error(error);
        process.exit(1);
    });
"><code>const hre <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"hardhat"</span>);

async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>) </span>{
    const { ethers } <span class="hljs-operator">=</span> hre;

    <span class="hljs-comment">//你对应的合约地址，多个的话可以写个函数读取</span>
    const contractAddresses <span class="hljs-operator">=</span> [
        <span class="hljs-string">"0x045d788952D4DA8aA1D0dEDc2fBe1dDeE387C018"</span>,
        <span class="hljs-comment">// ...</span>
    ];
    <span class="hljs-comment">//你对应的合约部署时的参数，多个的话可以写个函数读取</span>
    const constructorArgs <span class="hljs-operator">=</span> [
        [<span class="hljs-string">"Gobelin"</span>, <span class="hljs-string">"GOBELI"</span>, <span class="hljs-number">1000000000</span>],
        <span class="hljs-comment">// ...</span>
    ];

    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> contractAddresses.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        const <span class="hljs-keyword">address</span> <span class="hljs-operator">=</span> contractAddresses[i];
        const args <span class="hljs-operator">=</span> constructorArgs[i];
        console.log(`Verifying <span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">at</span> <span class="hljs-title">$</span></span>{<span class="hljs-keyword">address</span>}...`);
        await hre.run(<span class="hljs-string">"verify:verify"</span>, {
            <span class="hljs-keyword">address</span>,
            constructorArguments: args,
            # 你的合约文件名和合约名，多个的话写成函数传参形式替换
            <span class="hljs-class"><span class="hljs-keyword">contract</span>: "<span class="hljs-title">Token</span>.<span class="hljs-title">sol</span>:<span class="hljs-title">Token</span>",
            <span class="hljs-title">network</span>: "<span class="hljs-title">basegoerli</span>",
        });
        <span class="hljs-title">console</span>.<span class="hljs-title">log</span>(<span class="hljs-params">`Contract at ${<span class="hljs-keyword">address</span>} verified successfully.`</span>);
    }
}

<span class="hljs-title">main</span>(<span class="hljs-params"></span>)
    .<span class="hljs-title">then</span>(<span class="hljs-params">(<span class="hljs-params"></span>) => process.exit(<span class="hljs-params"><span class="hljs-number">0</span></span>)</span>)
    .<span class="hljs-title"><span class="hljs-keyword">catch</span></span>(<span class="hljs-params"><span class="hljs-keyword">error</span> => {
        console.<span class="hljs-keyword">error</span>(<span class="hljs-params"><span class="hljs-keyword">error</span></span>);
        process.exit(<span class="hljs-params"><span class="hljs-number">1</span></span>);
    }</span>);
</span></code></pre><p>3、如果你只有单个合约，那验证那就直接在命令行就可以解决了。对应的更改合约地址（contract_address），参数(arg1,arg2,arg3,…)就可以了,参数有多少个传多少个。</p><pre data-type="codeBlock" text="npx hardhat verify --network network_name contract_address arg1 arg2 arg3 ....
"><code>npx hardhat verify <span class="hljs-operator">-</span><span class="hljs-operator">-</span>network network_name contract_address arg1 arg2 arg3 ....
</code></pre><p>4、验证完以后的合约就有这个对钩啦。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a1aea16a9a19323411d70cabb721619a6f58c9197e9701e0d58ce875cb8766d3.png" alt="合约验证" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">合约验证</figcaption></figure><div data-type="subscribeButton" class="center-contents"><a class="email-subscribe-button" href="null">Subscribe</a></div><p>刚开始学写这些内容，如果对你有用的话，给我点个关注吧,Thanks♪(･ω･)ﾉ。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/runker54">https://twitter.com/runker54</a></p><pre data-type="codeBlock" text="
"><code></code></pre>]]></content:encoded>
            <author>runker54@newsletter.paragraph.com (Runker54)</author>
        </item>
        <item>
            <title><![CDATA[使用ethers.js在ScrollAlpha撸GETH]]></title>
            <link>https://paragraph.com/@runker54/ethers-js-scrollalpha-geth</link>
            <guid>9Uctan8ruxPOxsGtkuzc</guid>
            <pubDate>Tue, 18 Apr 2023 05:54:56 GMT</pubDate>
            <description><![CDATA[我是一个刚学ethers.js的小白。前段时间交互Scroll生态的时候，发现一个可以撸geth的机会，现在的geth越来越难领取，这个操作实践起来很简单，思路就是领取免费的USDC然后兑换ETH，我撸了几百个收手了。够我以后的测试用了。RPC、地址信息免费领取USDC的地址：0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942USDC Token地址：0xA0D71B9877f44C744546D649147E3F1e70a93760ScrollAlpha RPC: https://alpha-rpc.scroll.io/l2合约ABIerc20_abi.json 因为涉及USDC的转移，所以用ERC20的ABI中的transfer和balanceOf即可[{ "type": "function", "stateMutability": "nonpayable", "outputs": [ { "type": "bool", "name": "", "internalType": "bool" } ], "name": "transfer", "...]]></description>
            <content:encoded><![CDATA[<p>     我是一个刚学ethers.js的小白。前段时间交互Scroll生态的时候，发现一个可以撸geth的机会，现在的geth越来越难领取，这个操作实践起来很简单，思路就是领取免费的USDC然后兑换ETH，我撸了几百个收手了。够我以后的测试用了。</p><h3 id="h-rpc" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">RPC、地址信息</h3><ul><li><p>免费领取USDC的地址：0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942</p></li><li><p>USDC Token地址：0xA0D71B9877f44C744546D649147E3F1e70a93760</p></li><li><p>ScrollAlpha RPC: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://alpha-rpc.scroll.io/l2">https://alpha-rpc.scroll.io/l2</a></p></li></ul><h3 id="h-abi" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">合约ABI</h3><ul><li><p>erc20_abi.json</p><p>     因为涉及USDC的转移，所以用ERC20的ABI中的transfer和balanceOf即可</p><pre data-type="codeBlock" text="[{
        &quot;type&quot;: &quot;function&quot;,
        &quot;stateMutability&quot;: &quot;nonpayable&quot;,
        &quot;outputs&quot;: [
            {
                &quot;type&quot;: &quot;bool&quot;,
                &quot;name&quot;: &quot;&quot;,
                &quot;internalType&quot;: &quot;bool&quot;
            }
        ],
        &quot;name&quot;: &quot;transfer&quot;,
        &quot;inputs&quot;: [
            {
                &quot;type&quot;: &quot;address&quot;,
                &quot;name&quot;: &quot;to&quot;,
                &quot;internalType&quot;: &quot;address&quot;
            },
            {
                &quot;type&quot;: &quot;uint256&quot;,
                &quot;name&quot;: &quot;amount&quot;,
                &quot;internalType&quot;: &quot;uint256&quot;
            }
        ]
    },
    {
        &quot;type&quot;: &quot;function&quot;,
        &quot;stateMutability&quot;: &quot;view&quot;,
        &quot;outputs&quot;: [
            {
                &quot;type&quot;: &quot;uint256&quot;,
                &quot;name&quot;: &quot;&quot;,
                &quot;internalType&quot;: &quot;uint256&quot;
            }
        ],
        &quot;name&quot;: &quot;balanceOf&quot;,
        &quot;inputs&quot;: [
            {
                &quot;type&quot;: &quot;address&quot;,
                &quot;name&quot;: &quot;account&quot;,
                &quot;internalType&quot;: &quot;address&quot;
            }
        ]
    }
]
"><code><span class="hljs-selector-attr">[{        <span class="hljs-string">"type"</span>: <span class="hljs-string">"function"</span>,        <span class="hljs-string">"stateMutability"</span>: <span class="hljs-string">"nonpayable"</span>,        <span class="hljs-string">"outputs"</span>: [            {                <span class="hljs-string">"type"</span>: <span class="hljs-string">"bool"</span>,                <span class="hljs-string">"name"</span>: <span class="hljs-string">""</span>,                <span class="hljs-string">"internalType"</span>: <span class="hljs-string">"bool"</span>            }        ]</span>,
        "name": <span class="hljs-string">"transfer"</span>,
        <span class="hljs-string">"inputs"</span>: [
            {
                "type": <span class="hljs-string">"address"</span>,
                <span class="hljs-string">"name"</span>: <span class="hljs-string">"to"</span>,
                <span class="hljs-string">"internalType"</span>: <span class="hljs-string">"address"</span>
            },
            {
                "type": <span class="hljs-string">"uint256"</span>,
                <span class="hljs-string">"name"</span>: <span class="hljs-string">"amount"</span>,
                <span class="hljs-string">"internalType"</span>: <span class="hljs-string">"uint256"</span>
            }
        ]
    },
    {
        "type": <span class="hljs-string">"function"</span>,
        <span class="hljs-string">"stateMutability"</span>: <span class="hljs-string">"view"</span>,
        <span class="hljs-string">"outputs"</span>: [
            {
                "type": <span class="hljs-string">"uint256"</span>,
                <span class="hljs-string">"name"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"internalType"</span>: <span class="hljs-string">"uint256"</span>
            }
        ],
        "name": <span class="hljs-string">"balanceOf"</span>,
        <span class="hljs-string">"inputs"</span>: [
            {
                "type": <span class="hljs-string">"address"</span>,
                <span class="hljs-string">"name"</span>: <span class="hljs-string">"account"</span>,
                <span class="hljs-string">"internalType"</span>: <span class="hljs-string">"address"</span>
            }
        ]
    }
]
</code></pre></li><li><p>usdc_faucet_abi.json</p><p>     因为要和领取USDC的合约交互，所以还需要usdc_faucet的abi，在这个ABI中只用到了claim函数，所以可以把其它多于的部分删除。</p><pre data-type="codeBlock" text="[
    {
        &quot;type&quot;: &quot;function&quot;,
        &quot;stateMutability&quot;: &quot;nonpayable&quot;,
        &quot;outputs&quot;: [],
        &quot;name&quot;: &quot;claim&quot;,
        &quot;inputs&quot;: []
    }
]
"><code><span class="hljs-selector-attr">[    {        <span class="hljs-string">"type"</span>: <span class="hljs-string">"function"</span>,        <span class="hljs-string">"stateMutability"</span>: <span class="hljs-string">"nonpayable"</span>,        <span class="hljs-string">"outputs"</span>: []</span>,
        "name": <span class="hljs-string">"claim"</span>,
        <span class="hljs-string">"inputs"</span>: []
    }
]
</code></pre></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">代码准备</h3><ul><li><p>批量创建账户</p><pre data-type="codeBlock" text="const ethers = require(&apos;ethers&apos;);
const fs = require(&apos;fs&apos;);

// 批量创建账户函数
function createAccounts(filename, number) {
    for (let i = 0; i &lt; number; i++) {
        const wallet = ethers.Wallet.createRandom();
        fs.writeFileSync(`${filename}.txt`, wallet.address + &quot; &quot; + wallet.privateKey + &quot;\n&quot;, { flag: &apos;a&apos; });
        console.log(wallet.address, wallet.privateKey);
    }

}
// 在当前目录下创建localwallets.txt文件保存新创建的1000个账户信息
createAccounts(&quot;localwallets&quot;, 1000);
"><code>const ethers <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'ethers'</span>);
const fs <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);

<span class="hljs-comment">// 批量创建账户函数</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createAccounts</span>(<span class="hljs-params">filename, number</span>) </span>{
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> number; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        const wallet <span class="hljs-operator">=</span> ethers.Wallet.createRandom();
        fs.writeFileSync(`${filename}.txt`, wallet.<span class="hljs-built_in">address</span> <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> wallet.privateKey <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        console.log(wallet.<span class="hljs-built_in">address</span>, wallet.privateKey);
    }

}
<span class="hljs-comment">// 在当前目录下创建localwallets.txt文件保存新创建的1000个账户信息</span>
createAccounts(<span class="hljs-string">"localwallets"</span>, <span class="hljs-number">1000</span>);
</code></pre></li><li><p>发送ETH</p><pre data-type="codeBlock" text="// transfer eth
async function transfer_eth(wallet, to, value) {
    const tx = await wallet.sendTransaction({
        to: to,
        value: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    return tx.hash;
}
"><code><span class="hljs-comment">// transfer eth</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer_eth</span>(<span class="hljs-params">wallet, to, value</span>) </span>{
    const <span class="hljs-built_in">tx</span> <span class="hljs-operator">=</span> await wallet.sendTransaction({
        to: to,
        <span class="hljs-built_in">value</span>: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">tx</span>.hash;
}
</code></pre></li><li><p>领取USDC</p><pre data-type="codeBlock" text="// claim usdc token
async function claim_usdc(wallet) {
    const contract = usdc_faucet_contract.connect(wallet);
    const tx = await contract.claim({ gasPrice: await get_gas_price() });
    return tx.hash;
}
"><code><span class="hljs-comment">// claim usdc token</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">claim_usdc</span>(<span class="hljs-params">wallet</span>) </span>{
    const <span class="hljs-class"><span class="hljs-keyword">contract</span> = <span class="hljs-title">usdc_faucet_contract</span>.<span class="hljs-title">connect</span>(<span class="hljs-params">wallet</span>);
    <span class="hljs-title">const</span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span> = <span class="hljs-title">await</span> <span class="hljs-title"><span class="hljs-keyword">contract</span></span>.<span class="hljs-title">claim</span>(<span class="hljs-params">{ gasPrice: await get_gas_price(<span class="hljs-params"></span>) }</span>);
    <span class="hljs-title"><span class="hljs-keyword">return</span></span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span>.<span class="hljs-title">hash</span>;
}
</span></code></pre></li><li><p>转移USDC Token</p><pre data-type="codeBlock" text="//transfer usdc token
async function transfer_token(wallet, to, value) {
    const contract = usdc_token_contract.connect(wallet);
    const tx = await contract.transfer(to, ethers.utils.parseEther(value));
    return tx.hash;
}
"><code><span class="hljs-comment">//transfer usdc token</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer_token</span>(<span class="hljs-params">wallet, to, value</span>) </span>{
    const <span class="hljs-class"><span class="hljs-keyword">contract</span> = <span class="hljs-title">usdc_token_contract</span>.<span class="hljs-title">connect</span>(<span class="hljs-params">wallet</span>);
    <span class="hljs-title">const</span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span> = <span class="hljs-title">await</span> <span class="hljs-title"><span class="hljs-keyword">contract</span></span>.<span class="hljs-title">transfer</span>(<span class="hljs-params">to, ethers.utils.parseEther(<span class="hljs-params">value</span>)</span>);
    <span class="hljs-title"><span class="hljs-keyword">return</span></span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span>.<span class="hljs-title">hash</span>;
}
</span></code></pre></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">第一套方案</h3><p>     逐个账户进行，转移ETH到账户下，账户领取USDC，账户发USDC到归集地址，然后发送剩余ETH到下一个账户，循环进行。代码如下：</p><pre data-type="codeBlock" text="const ethers = require(&quot;ethers&quot;);
const fs = require(&apos;fs&apos;);
const { promisify } = require(&apos;util&apos;);
const readFileAsync = promisify(fs.readFile);
// provider
const scrollAlphaProvider = new ethers.providers.JsonRpcProvider(&apos;https://alpha-rpc.scroll.io/l2&apos;);
// contract abi
// 导入你的合约abi  json文件 需要自己修改
const usdc_abi = require(&quot;../abi_source/usdc_faucet_abi.json&quot;);
const usdc_token_abi = require(&quot;../abi_source/usdc_token_abi.json&quot;);

// contract address
// 导入交互的合约地址
const usdc_faucet = &quot;0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942&quot;;
const usdc_token = &quot;0xA0D71B9877f44C744546D649147E3F1e70a93760&quot;;
// contract
// 创建你的合约实例
// usdc faucet
const usdc_faucet_contract = new ethers.Contract(usdc_faucet, usdc_abi, scrollAlphaProvider);
// usdc token
const usdc_token_contract = new ethers.Contract(usdc_token, usdc_token_abi, scrollAlphaProvider);


// 获取账户列表
async function get_account_list(filename) {
    const contents = await readFileAsync(`${filename}.txt`, &apos;utf8&apos;);
    let account_list = [];
    const walletsList = contents.split(&quot;\n&quot;);
    for (let i = 0; i &lt; walletsList.length; i++) {
        result = walletsList[i].split(&quot; &quot;);
        result_list = [result[0], result[1]];
        account_list.push(result_list);
    }
    return account_list;
}

// 计算当前gas价格
async function get_gas_price() {
    gas_price = await scrollAlphaProvider.getGasPrice();
    result = Number(gas_price);
    return result;
}


// 获取余额
async function get_balance(wallets) {
    balance = await scrollAlphaProvider.getBalance(wallets.address);
    result = ethers.utils.formatEther(balance);
    return result;
}


// 转移eth
async function transfer_eth(wallet, to, value) {
    const tx = await wallet.sendTransaction({
        to: to,
        value: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    return tx.hash;
}


// 主函数,需要保证第一个账户有足够的eth
const main = async () =&gt; {
    // 从文件中读取账户列表,需要自己修改传入的文件名
    const account_list = await get_account_list(&quot;xxx&quot;);
    // 接收usdc的钱包的地址,需要自己修改
    const receipt_usdc_wallet_address = &quot;......&quot;
    for (let i = 0; i &lt; account_list.length; i++) {
        // 创建钱包对象
        const wallet1 = new ethers.Wallet(account_list[i][1], scrollAlphaProvider);
        const wallet2 = new ethers.Wallet(account_list[i+1][1], scrollAlphaProvider);// 超过列表范围没有做异常捕获
        //claim usdc
        try{
            await claim_usdc(wallet1);
        }catch(e){
            fs.writeFileSync(&apos;claimerror.txt&apos;, `${account_list[i][0]} ${account_list[i][1]} \n`, { flag: &apos;a&apos; });
        }
        // transfer usdc
        try{
            // 每次固定领取到的是5000个usdc，所以这里写死了
            await transfer_usdc(wallet1, receipt_usdc_wallet_address, &quot;5000&quot;);
        }catch(e){
            fs.writeFileSync(&apos;transfererror.txt&apos;, `${account_list[i][0]} ${account_list[i][1]} \n`, { flag: &apos;a&apos; });
        }
        // transfer eth 发送eth到下一个账户执行
        // 设置需要花费的gas总量
        let gas_total = 100000000000000;
        while (true) {
            try {
                let wallet_balance = (await wallet1.getBalance()) - gas_total;
                let wallet_balance_string = ethers.BigNumber.from(wallet_balance.toString());
                await transfer_eth(wallet1, wallet2.address, wallet_balance_string);
                console.log(&quot;eth transfer success&quot;)
                break;
            } catch (e) {
                console.log(e);
                console.log(&quot;gas not enough&quot;)
                gas_total = gas_total + 50000000000000;
                continue;
            }
        }
    }
}

main();
"><code>const ethers <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"ethers"</span>);
const fs <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
const { promisify } <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
const readFileAsync <span class="hljs-operator">=</span> promisify(fs.readFile);
<span class="hljs-comment">// provider</span>
const scrollAlphaProvider <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.providers.JsonRpcProvider(<span class="hljs-string">'https://alpha-rpc.scroll.io/l2'</span>);
<span class="hljs-comment">// contract abi</span>
<span class="hljs-comment">// 导入你的合约abi  json文件 需要自己修改</span>
const usdc_abi <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"../abi_source/usdc_faucet_abi.json"</span>);
const usdc_token_abi <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"../abi_source/usdc_token_abi.json"</span>);

<span class="hljs-comment">// contract address</span>
<span class="hljs-comment">// 导入交互的合约地址</span>
const usdc_faucet <span class="hljs-operator">=</span> <span class="hljs-string">"0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942"</span>;
const usdc_token <span class="hljs-operator">=</span> <span class="hljs-string">"0xA0D71B9877f44C744546D649147E3F1e70a93760"</span>;
<span class="hljs-comment">// contract</span>
<span class="hljs-comment">// 创建你的合约实例</span>
<span class="hljs-comment">// usdc faucet</span>
const usdc_faucet_contract <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Contract(usdc_faucet, usdc_abi, scrollAlphaProvider);
<span class="hljs-comment">// usdc token</span>
const usdc_token_contract <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Contract(usdc_token, usdc_token_abi, scrollAlphaProvider);


<span class="hljs-comment">// 获取账户列表</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_account_list</span>(<span class="hljs-params">filename</span>) </span>{
    const contents <span class="hljs-operator">=</span> await readFileAsync(`${filename}.txt`, <span class="hljs-string">'utf8'</span>);
    let account_list <span class="hljs-operator">=</span> [];
    const walletsList <span class="hljs-operator">=</span> contents.split(<span class="hljs-string">"\n"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> walletsList.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        result <span class="hljs-operator">=</span> walletsList[i].split(<span class="hljs-string">" "</span>);
        result_list <span class="hljs-operator">=</span> [result[<span class="hljs-number">0</span>], result[<span class="hljs-number">1</span>]];
        account_list.<span class="hljs-built_in">push</span>(result_list);
    }
    <span class="hljs-keyword">return</span> account_list;
}

<span class="hljs-comment">// 计算当前gas价格</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_gas_price</span>(<span class="hljs-params"></span>) </span>{
    gas_price <span class="hljs-operator">=</span> await scrollAlphaProvider.getGasPrice();
    result <span class="hljs-operator">=</span> Number(gas_price);
    <span class="hljs-keyword">return</span> result;
}


<span class="hljs-comment">// 获取余额</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_balance</span>(<span class="hljs-params">wallets</span>) </span>{
    balance <span class="hljs-operator">=</span> await scrollAlphaProvider.getBalance(wallets.<span class="hljs-built_in">address</span>);
    result <span class="hljs-operator">=</span> ethers.utils.formatEther(balance);
    <span class="hljs-keyword">return</span> result;
}


<span class="hljs-comment">// 转移eth</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer_eth</span>(<span class="hljs-params">wallet, to, value</span>) </span>{
    const <span class="hljs-built_in">tx</span> <span class="hljs-operator">=</span> await wallet.sendTransaction({
        to: to,
        <span class="hljs-built_in">value</span>: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">tx</span>.hash;
}


<span class="hljs-comment">// 主函数,需要保证第一个账户有足够的eth</span>
const main <span class="hljs-operator">=</span> async () <span class="hljs-operator">=</span><span class="hljs-operator">></span> {
    <span class="hljs-comment">// 从文件中读取账户列表,需要自己修改传入的文件名</span>
    const account_list <span class="hljs-operator">=</span> await get_account_list(<span class="hljs-string">"xxx"</span>);
    <span class="hljs-comment">// 接收usdc的钱包的地址,需要自己修改</span>
    const receipt_usdc_wallet_address <span class="hljs-operator">=</span> <span class="hljs-string">"......"</span>
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> account_list.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        <span class="hljs-comment">// 创建钱包对象</span>
        const wallet1 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(account_list[i][<span class="hljs-number">1</span>], scrollAlphaProvider);
        const wallet2 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(account_list[i<span class="hljs-operator">+</span><span class="hljs-number">1</span>][<span class="hljs-number">1</span>], scrollAlphaProvider);<span class="hljs-comment">// 超过列表范围没有做异常捕获</span>
        <span class="hljs-comment">//claim usdc</span>
        <span class="hljs-keyword">try</span>{
            await claim_usdc(wallet1);
        }<span class="hljs-keyword">catch</span>(e){
            fs.writeFileSync(<span class="hljs-string">'claimerror.txt'</span>, `${account_list[i][<span class="hljs-number">0</span>]} ${account_list[i][<span class="hljs-number">1</span>]} \n`, { flag: <span class="hljs-string">'a'</span> });
        }
        <span class="hljs-comment">// transfer usdc</span>
        <span class="hljs-keyword">try</span>{
            <span class="hljs-comment">// 每次固定领取到的是5000个usdc，所以这里写死了</span>
            await transfer_usdc(wallet1, receipt_usdc_wallet_address, <span class="hljs-string">"5000"</span>);
        }<span class="hljs-keyword">catch</span>(e){
            fs.writeFileSync(<span class="hljs-string">'transfererror.txt'</span>, `${account_list[i][<span class="hljs-number">0</span>]} ${account_list[i][<span class="hljs-number">1</span>]} \n`, { flag: <span class="hljs-string">'a'</span> });
        }
        <span class="hljs-comment">// transfer eth 发送eth到下一个账户执行</span>
        <span class="hljs-comment">// 设置需要花费的gas总量</span>
        let gas_total <span class="hljs-operator">=</span> <span class="hljs-number">100000000000000</span>;
        <span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>) {
            <span class="hljs-keyword">try</span> {
                let wallet_balance <span class="hljs-operator">=</span> (await wallet1.getBalance()) <span class="hljs-operator">-</span> gas_total;
                let wallet_balance_string <span class="hljs-operator">=</span> ethers.BigNumber.from(wallet_balance.toString());
                await transfer_eth(wallet1, wallet2.<span class="hljs-built_in">address</span>, wallet_balance_string);
                console.log(<span class="hljs-string">"eth transfer success"</span>)
                <span class="hljs-keyword">break</span>;
            } <span class="hljs-keyword">catch</span> (e) {
                console.log(e);
                console.log(<span class="hljs-string">"gas not enough"</span>)
                gas_total <span class="hljs-operator">=</span> gas_total <span class="hljs-operator">+</span> <span class="hljs-number">50000000000000</span>;
                <span class="hljs-keyword">continue</span>;
            }
        }
    }
}

main();
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">第二套方案</h3><p>     就是把三个步骤分开，分为统一发送eth，统一claim, 统一transfer usdc。实际运行的时候，让发送eth先跑一会，等待一段时候后在执行claim，我再实测的时候发现claim的速度是比发送eth要快的。transfer usdc同理。</p><p>transfer_eth.js</p><p>批量转移eth。</p><pre data-type="codeBlock" text="const ethers = require(&quot;ethers&quot;);
const fs = require(&apos;fs&apos;);
const { promisify } = require(&apos;util&apos;);
const readFileAsync = promisify(fs.readFile);
// provider
const scrollAlphaProvider = new ethers.providers.JsonRpcProvider(&apos;https://alpha-rpc.scroll.io/l2&apos;);
//wallets
//你发送eth的钱包私钥，需要自己修改
const send_key = &quot;0x0000000&quot;;
const send_wallets = new ethers.Wallet(send_key, scrollAlphaProvider);

// 获取账户列表
async function get_account_list(filename) {
    const contents = await readFileAsync(`${filename}.txt`, &apos;utf8&apos;);
    let account_list = [];
    const walletsList = contents.split(&quot;\n&quot;);
    for (let i = 0; i &lt; walletsList.length; i++) {
        result = walletsList[i].split(&quot; &quot;);
        result_list = [result[0], result[1]];
        account_list.push(result_list);
    }
    return account_list;
}

// 计算当前gas价格
async function get_gas_price() {
    gas_price = await scrollAlphaProvider.getGasPrice();
    result = 2 * Number(gas_price);
    return result;
}


// 获取余额
async function get_balance(wallets) {
    balance = await scrollAlphaProvider.getBalance(wallets.address);
    result = ethers.utils.formatEther(balance);
    return result;
}


// 转移eth
async function transfer_eth(wallet, to, value) {
    const tx = await wallet.sendTransaction({
        to: to,
        value: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    return tx.hash;
}

// transfer主函数，批量发送eth。
const main = async () =&gt; {
    //从文件中读取账户列表,需要自己修改传入的文件名
    const account_list = await get_account_list(“xxx”);
    for (let i = 0; i &lt; account_list.length; i++) {
        const wallet1 = new ethers.Wallet(account_list[i][1], scrollAlphaProvider);
        console.log(send_wallets.address, wallet1.address)
        try {
            // 实测发现每个账户转移0.0008eth就可以了，gas费用高的话可以适当调高。
            await transfer_eth(send_wallets, wallet1.address, &quot;0.0008&quot;);
            fs.writeFileSync(&apos;transfer_success_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        } catch (e) {
            fs.writeFileSync(&apos;transfer_fail_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        }

    }

}

main();
"><code>const ethers <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"ethers"</span>);
const fs <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
const { promisify } <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
const readFileAsync <span class="hljs-operator">=</span> promisify(fs.readFile);
<span class="hljs-comment">// provider</span>
const scrollAlphaProvider <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.providers.JsonRpcProvider(<span class="hljs-string">'https://alpha-rpc.scroll.io/l2'</span>);
<span class="hljs-comment">//wallets</span>
<span class="hljs-comment">//你发送eth的钱包私钥，需要自己修改</span>
const send_key <span class="hljs-operator">=</span> <span class="hljs-string">"0x0000000"</span>;
const send_wallets <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(send_key, scrollAlphaProvider);

<span class="hljs-comment">// 获取账户列表</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_account_list</span>(<span class="hljs-params">filename</span>) </span>{
    const contents <span class="hljs-operator">=</span> await readFileAsync(`${filename}.txt`, <span class="hljs-string">'utf8'</span>);
    let account_list <span class="hljs-operator">=</span> [];
    const walletsList <span class="hljs-operator">=</span> contents.split(<span class="hljs-string">"\n"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> walletsList.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        result <span class="hljs-operator">=</span> walletsList[i].split(<span class="hljs-string">" "</span>);
        result_list <span class="hljs-operator">=</span> [result[<span class="hljs-number">0</span>], result[<span class="hljs-number">1</span>]];
        account_list.<span class="hljs-built_in">push</span>(result_list);
    }
    <span class="hljs-keyword">return</span> account_list;
}

<span class="hljs-comment">// 计算当前gas价格</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_gas_price</span>(<span class="hljs-params"></span>) </span>{
    gas_price <span class="hljs-operator">=</span> await scrollAlphaProvider.getGasPrice();
    result <span class="hljs-operator">=</span> <span class="hljs-number">2</span> <span class="hljs-operator">*</span> Number(gas_price);
    <span class="hljs-keyword">return</span> result;
}


<span class="hljs-comment">// 获取余额</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_balance</span>(<span class="hljs-params">wallets</span>) </span>{
    balance <span class="hljs-operator">=</span> await scrollAlphaProvider.getBalance(wallets.<span class="hljs-built_in">address</span>);
    result <span class="hljs-operator">=</span> ethers.utils.formatEther(balance);
    <span class="hljs-keyword">return</span> result;
}


<span class="hljs-comment">// 转移eth</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer_eth</span>(<span class="hljs-params">wallet, to, value</span>) </span>{
    const <span class="hljs-built_in">tx</span> <span class="hljs-operator">=</span> await wallet.sendTransaction({
        to: to,
        <span class="hljs-built_in">value</span>: ethers.utils.parseEther(value),
        gasPrice: await get_gas_price(),
    });
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">tx</span>.hash;
}

<span class="hljs-comment">// transfer主函数，批量发送eth。</span>
const main <span class="hljs-operator">=</span> async () <span class="hljs-operator">=</span><span class="hljs-operator">></span> {
    <span class="hljs-comment">//从文件中读取账户列表,需要自己修改传入的文件名</span>
    const account_list <span class="hljs-operator">=</span> await get_account_list(“xxx”);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> account_list.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        const wallet1 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(account_list[i][<span class="hljs-number">1</span>], scrollAlphaProvider);
        console.log(send_wallets.<span class="hljs-built_in">address</span>, wallet1.<span class="hljs-built_in">address</span>)
        <span class="hljs-keyword">try</span> {
            <span class="hljs-comment">// 实测发现每个账户转移0.0008eth就可以了，gas费用高的话可以适当调高。</span>
            await transfer_eth(send_wallets, wallet1.<span class="hljs-built_in">address</span>, <span class="hljs-string">"0.0008"</span>);
            fs.writeFileSync(<span class="hljs-string">'transfer_success_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        } <span class="hljs-keyword">catch</span> (e) {
            fs.writeFileSync(<span class="hljs-string">'transfer_fail_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        }

    }

}

main();
</code></pre><p>claim_usdc.js</p><p>统一领取免费的USDC Token</p><pre data-type="codeBlock" text="const ethers = require(&quot;ethers&quot;);
const fs = require(&apos;fs&apos;);
const { promisify } = require(&apos;util&apos;);
const readFileAsync = promisify(fs.readFile);
require(&quot;dotenv&quot;).config();
// provider
const scrollAlphaProvider = new ethers.providers.JsonRpcProvider(&apos;https://alpha-rpc.scroll.io/l2&apos;);
// contract
// usdc faucet
const usdc_faucet = &quot;0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942&quot;;
// 传入和合约交互的abi的json文件, 需要自己修改
const usdc_abi = require(&quot;../abi_source/usdc_faucet_abi.json&quot;);
const usdc_faucet_contract = new ethers.Contract(usdc_faucet, usdc_abi, scrollAlphaProvider);

// 获取账户列表
async function get_account_list(filename) {
    const contents = await readFileAsync(`${filename}.txt`, &apos;utf8&apos;);
    let account_list = [];
    const walletsList = contents.split(&quot;\n&quot;);
    for (let i = 0; i &lt; walletsList.length; i++) {
        result = walletsList[i].split(&quot; &quot;);
        result_list = [result[0], result[1]];
        account_list.push(result_list);
    }
    return account_list;
}

// 计算当前gas价格
async function get_gas_price() {
    gas_price = await scrollAlphaProvider.getGasPrice();
    result = 2 * Number(gas_price);
    return result;
}


// claim token
async function claim_usdc(wallet) {
    const contract = usdc_faucet_contract.connect(wallet);
    const tx = await contract.claim();
    return tx.hash;
}

// transfer主函数
const main = async () =&gt; {
    //从文件中读取账户列表,需要自己修改传入的文件名
    const account_list = await get_account_list(&quot;xxx&quot;);
    for (let i = 0; i &lt; account_list.length; i++) {
        const wallet1 = new ethers.Wallet(account_list[i][1], scrollAlphaProvider);
        console.log(wallet1.address)
        try {
            await claim_usdc(wallet1);
            console.log(&quot;claim_usdc success&quot;);
            fs.writeFileSync(&apos;claimsuccess_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        } catch (e) {
            fs.writeFileSync(&apos;claimfail_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        }
    }
}
main();
"><code>const ethers <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"ethers"</span>);
const fs <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
const { promisify } <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
const readFileAsync <span class="hljs-operator">=</span> promisify(fs.readFile);
<span class="hljs-built_in">require</span>(<span class="hljs-string">"dotenv"</span>).config();
<span class="hljs-comment">// provider</span>
const scrollAlphaProvider <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.providers.JsonRpcProvider(<span class="hljs-string">'https://alpha-rpc.scroll.io/l2'</span>);
<span class="hljs-comment">// contract</span>
<span class="hljs-comment">// usdc faucet</span>
const usdc_faucet <span class="hljs-operator">=</span> <span class="hljs-string">"0xeF71Ddc12Bac8A2ba0b9068b368189FFa2628942"</span>;
<span class="hljs-comment">// 传入和合约交互的abi的json文件, 需要自己修改</span>
const usdc_abi <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"../abi_source/usdc_faucet_abi.json"</span>);
const usdc_faucet_contract <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Contract(usdc_faucet, usdc_abi, scrollAlphaProvider);

<span class="hljs-comment">// 获取账户列表</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_account_list</span>(<span class="hljs-params">filename</span>) </span>{
    const contents <span class="hljs-operator">=</span> await readFileAsync(`${filename}.txt`, <span class="hljs-string">'utf8'</span>);
    let account_list <span class="hljs-operator">=</span> [];
    const walletsList <span class="hljs-operator">=</span> contents.split(<span class="hljs-string">"\n"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> walletsList.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        result <span class="hljs-operator">=</span> walletsList[i].split(<span class="hljs-string">" "</span>);
        result_list <span class="hljs-operator">=</span> [result[<span class="hljs-number">0</span>], result[<span class="hljs-number">1</span>]];
        account_list.<span class="hljs-built_in">push</span>(result_list);
    }
    <span class="hljs-keyword">return</span> account_list;
}

<span class="hljs-comment">// 计算当前gas价格</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_gas_price</span>(<span class="hljs-params"></span>) </span>{
    gas_price <span class="hljs-operator">=</span> await scrollAlphaProvider.getGasPrice();
    result <span class="hljs-operator">=</span> <span class="hljs-number">2</span> <span class="hljs-operator">*</span> Number(gas_price);
    <span class="hljs-keyword">return</span> result;
}


<span class="hljs-comment">// claim token</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">claim_usdc</span>(<span class="hljs-params">wallet</span>) </span>{
    const <span class="hljs-class"><span class="hljs-keyword">contract</span> = <span class="hljs-title">usdc_faucet_contract</span>.<span class="hljs-title">connect</span>(<span class="hljs-params">wallet</span>);
    <span class="hljs-title">const</span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span> = <span class="hljs-title">await</span> <span class="hljs-title"><span class="hljs-keyword">contract</span></span>.<span class="hljs-title">claim</span>(<span class="hljs-params"></span>);
    <span class="hljs-title"><span class="hljs-keyword">return</span></span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span>.<span class="hljs-title">hash</span>;
}

<span class="hljs-comment">// transfer主函数</span>
<span class="hljs-title">const</span> <span class="hljs-title">main</span> = <span class="hljs-title">async</span> (<span class="hljs-params"></span>) => </span>{
    <span class="hljs-comment">//从文件中读取账户列表,需要自己修改传入的文件名</span>
    const account_list <span class="hljs-operator">=</span> await get_account_list(<span class="hljs-string">"xxx"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> account_list.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        const wallet1 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(account_list[i][<span class="hljs-number">1</span>], scrollAlphaProvider);
        console.log(wallet1.<span class="hljs-built_in">address</span>)
        <span class="hljs-keyword">try</span> {
            await claim_usdc(wallet1);
            console.log(<span class="hljs-string">"claim_usdc success"</span>);
            fs.writeFileSync(<span class="hljs-string">'claimsuccess_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        } <span class="hljs-keyword">catch</span> (e) {
            fs.writeFileSync(<span class="hljs-string">'claimfail_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        }
    }
}
main();
</code></pre><p>transfer_usdc.js</p><p>统一发送usdc到归集账户，然后去uniswap兑换就可以啦。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://uniswap-v3.scroll.io/#/swap">https://uniswap-v3.scroll.io/#/swap</a></p><pre data-type="codeBlock" text="const ethers = require(&quot;ethers&quot;);
const fs = require(&apos;fs&apos;);
const { promisify } = require(&apos;util&apos;);
const readFileAsync = promisify(fs.readFile);
// provider
const scrollAlphaProvider = new ethers.providers.JsonRpcProvider(&apos;https://alpha-rpc.scroll.io/l2&apos;);

// usdc token
const usdc_token = &quot;0xA0D71B9877f44C744546D649147E3F1e70a93760&quot;;
// 传入和合约交互的abi的json文件, 需要自己修改
const usdc_token_abi = require(&quot;../abi_source/usdc_token_abi.json&quot;);
const usdc_token_contract = new ethers.Contract(usdc_token, usdc_token_abi, scrollAlphaProvider);


// 获取账户列表
async function get_account_list(filename) {
    const contents = await readFileAsync(`${filename}.txt`, &apos;utf8&apos;);
    let account_list = [];
    const walletsList = contents.split(&quot;\n&quot;);
    for (let i = 0; i &lt; walletsList.length; i++) {
        result = walletsList[i].split(&quot; &quot;);
        result_list = [result[0], result[1]];
        account_list.push(result_list);
    }
    return account_list;
}


// 转移token
async function transfer_token(wallet, to, value) {
    const contract = usdc_token_contract.connect(wallet);
    const tx = await contract.transfer(to, ethers.utils.parseEther(value));
    return tx.hash;
}


// transfer主函数
const main = async () =&gt; {
    // 创建一个接收usdc的地址, 需要自己修改
    const receipt_usdc_address = &quot;.......&quot;
    // 传入账户列表的文件名, 需要自己修改
    const account_list = await get_account_list(&quot;xxx&quot;);
    for (let i = 0; i &lt; account_list.length; i++) {
        const wallet1 = new ethers.Wallet(account_list[i][1], scrollAlphaProvider);
        console.log(wallet1.address)
        try {
            await transfer_token(wallet1, receipt_usdc_address, &quot;5000&quot;);
            console.log(&quot;send success&quot;);
            fs.writeFileSync(&apos;sendsuccess_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        } catch (e) {
            fs.writeFileSync(&apos;sendfail_local1.txt&apos;, account_list[i][0] + &quot; &quot; + account_list[i][1] + &quot;\n&quot;, { flag: &apos;a&apos; });
        }
    }
}
main();
"><code>const ethers <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"ethers"</span>);
const fs <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
const { promisify } <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
const readFileAsync <span class="hljs-operator">=</span> promisify(fs.readFile);
<span class="hljs-comment">// provider</span>
const scrollAlphaProvider <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.providers.JsonRpcProvider(<span class="hljs-string">'https://alpha-rpc.scroll.io/l2'</span>);

<span class="hljs-comment">// usdc token</span>
const usdc_token <span class="hljs-operator">=</span> <span class="hljs-string">"0xA0D71B9877f44C744546D649147E3F1e70a93760"</span>;
<span class="hljs-comment">// 传入和合约交互的abi的json文件, 需要自己修改</span>
const usdc_token_abi <span class="hljs-operator">=</span> <span class="hljs-built_in">require</span>(<span class="hljs-string">"../abi_source/usdc_token_abi.json"</span>);
const usdc_token_contract <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Contract(usdc_token, usdc_token_abi, scrollAlphaProvider);


<span class="hljs-comment">// 获取账户列表</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">get_account_list</span>(<span class="hljs-params">filename</span>) </span>{
    const contents <span class="hljs-operator">=</span> await readFileAsync(`${filename}.txt`, <span class="hljs-string">'utf8'</span>);
    let account_list <span class="hljs-operator">=</span> [];
    const walletsList <span class="hljs-operator">=</span> contents.split(<span class="hljs-string">"\n"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> walletsList.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        result <span class="hljs-operator">=</span> walletsList[i].split(<span class="hljs-string">" "</span>);
        result_list <span class="hljs-operator">=</span> [result[<span class="hljs-number">0</span>], result[<span class="hljs-number">1</span>]];
        account_list.<span class="hljs-built_in">push</span>(result_list);
    }
    <span class="hljs-keyword">return</span> account_list;
}


<span class="hljs-comment">// 转移token</span>
async <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer_token</span>(<span class="hljs-params">wallet, to, value</span>) </span>{
    const <span class="hljs-class"><span class="hljs-keyword">contract</span> = <span class="hljs-title">usdc_token_contract</span>.<span class="hljs-title">connect</span>(<span class="hljs-params">wallet</span>);
    <span class="hljs-title">const</span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span> = <span class="hljs-title">await</span> <span class="hljs-title"><span class="hljs-keyword">contract</span></span>.<span class="hljs-title">transfer</span>(<span class="hljs-params">to, ethers.utils.parseEther(<span class="hljs-params">value</span>)</span>);
    <span class="hljs-title"><span class="hljs-keyword">return</span></span> <span class="hljs-title"><span class="hljs-built_in">tx</span></span>.<span class="hljs-title">hash</span>;
}


<span class="hljs-comment">// transfer主函数</span>
<span class="hljs-title">const</span> <span class="hljs-title">main</span> = <span class="hljs-title">async</span> (<span class="hljs-params"></span>) => </span>{
    <span class="hljs-comment">// 创建一个接收usdc的地址, 需要自己修改</span>
    const receipt_usdc_address <span class="hljs-operator">=</span> <span class="hljs-string">"......."</span>
    <span class="hljs-comment">// 传入账户列表的文件名, 需要自己修改</span>
    const account_list <span class="hljs-operator">=</span> await get_account_list(<span class="hljs-string">"xxx"</span>);
    <span class="hljs-keyword">for</span> (let i <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; i <span class="hljs-operator">&#x3C;</span> account_list.<span class="hljs-built_in">length</span>; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        const wallet1 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> ethers.Wallet(account_list[i][<span class="hljs-number">1</span>], scrollAlphaProvider);
        console.log(wallet1.<span class="hljs-built_in">address</span>)
        <span class="hljs-keyword">try</span> {
            await transfer_token(wallet1, receipt_usdc_address, <span class="hljs-string">"5000"</span>);
            console.log(<span class="hljs-string">"send success"</span>);
            fs.writeFileSync(<span class="hljs-string">'sendsuccess_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        } <span class="hljs-keyword">catch</span> (e) {
            fs.writeFileSync(<span class="hljs-string">'sendfail_local1.txt'</span>, account_list[i][<span class="hljs-number">0</span>] <span class="hljs-operator">+</span> <span class="hljs-string">" "</span> <span class="hljs-operator">+</span> account_list[i][<span class="hljs-number">1</span>] <span class="hljs-operator">+</span> <span class="hljs-string">"\n"</span>, { flag: <span class="hljs-string">'a'</span> });
        }
    }
}
main();
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">总结</h3><p>     在我开始发现这个的时候5000usdc能换取0.012个eth,2023年4月18日13:41:50现在好像只能换取0.005个了，但是都还有4倍多的收益，缺eth的可以搞一下，我搞了几百个就没搞了，也够我测试用了。      我觉得凡是测试网有免费claim代币的，且有池子的应该都有这种撸eth的机会。从此不在为GETH领不到而发愁了。。。</p><p>如果觉得对你有用的话，给我点个关注。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/runker54">https://twitter.com/runker54</a></p>]]></content:encoded>
            <author>runker54@newsletter.paragraph.com (Runker54)</author>
        </item>
    </channel>
</rss>