<?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>junjie9021</title>
        <link>https://paragraph.com/@junjie9021-3</link>
        <description>不定期分享姿势, 代码教程同步上传
推特: https://twitter.com/junjie9021
lens: https://lenster.xyz/u/0x049
github: https://github.com/junjie9021/simple-demo
</description>
        <lastBuildDate>Tue, 25 Aug 2026 12:35:38 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>junjie9021</title>
            <url>https://storage.googleapis.com/papyrus_images/4b7ff6c236094420b583822f1f481d172296278d585b4a416643b8c6d2337720.jpg</url>
            <link>https://paragraph.com/@junjie9021-3</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Linea 网络存款交互代码教程]]></title>
            <link>https://paragraph.com/@junjie9021-3/linea</link>
            <guid>4DGXZJjZOsgTq5WmRcXz</guid>
            <pubDate>Thu, 13 Apr 2023 15:03:00 GMT</pubDate>
            <description><![CDATA[小狐狸母公司 ConsenSys 的 zkevm 链 Linea 存款代码交互教程 存款代码""" pip install web3==5.29.1 """ import web3 import math import time import requests headers = { 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, api='https://rpc.ankr.com/eth_goerli', chainid=5, proxies=None, timeout=30): self.api = api self.chainid = chainid self.proxies = pro...]]></description>
            <content:encoded><![CDATA[<p>小狐狸母公司 ConsenSys 的 zkevm 链 Linea 存款代码交互教程</p><p>存款代码</p><pre data-type="codeBlock" text="&quot;&quot;&quot;
pip install web3==5.29.1
&quot;&quot;&quot;
import web3
import math
import time
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, api=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.api = api
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_current_block(self):
        &quot;&quot;&quot;获取最新区块&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_blockNumber&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_block_detail(self, number):
        &quot;&quot;&quot;获取区块hash&quot;&quot;&quot;
        if isinstance(number, int):
            number = hex(number)
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBlockByNumber&quot;,&quot;params&quot;:[number,True],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gasprice&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_max_gas_price(self):
        &quot;&quot;&quot;(base*2 + Priority) * gasLimit&quot;&quot;&quot;
        res = self.get_fee_history()
        base = int(res[&apos;result&apos;][&apos;baseFeePerGas&apos;][-1], 16)
        res = self.get_max_PriorityFeePerGas()
        priority = int(res[&apos;result&apos;], 16)
        return base * 2 + priority

    def get_fee_history(self):
        &quot;&quot;&quot;获取历史gasfee&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_feeHistory&quot;,&quot;params&quot;:[&quot;0x1&quot;, &quot;latest&quot;, []],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_max_PriorityFeePerGas(self):
        &quot;&quot;&quot;获取Priority&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_maxPriorityFeePerGas&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_limit(self, from_, to, data):
        &quot;&quot;&quot;call计算gaslimit&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_estimateGas&quot;,&quot;params&quot;:[{&quot;from&quot;: from_, &quot;to&quot;: to, &quot;data&quot;: data}],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def call(self, to, data):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_call&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}, &quot;latest&quot;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()#(int(res.json()[&apos;result&apos;], 16)) / math.pow(10,18)

    def transfer(self, account, to, amount, gaslimit, **kw):
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
    def transfer_eip1559(self, account, to, amount, gaslimit=21000, priority_fee=None, max_gas_fee=None, **kw):
        &quot;&quot;&quot;eip 1559发送tx, 更节省gas&quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        if not priority_fee:
            priority_fee = self.get_max_PriorityFeePerGas()[&apos;result&apos;]
        priority_fee = int(priority_fee, 16) if not isinstance(priority_fee, int) else priority_fee
        if not max_gas_fee:
            basefee = int(self.get_fee_history()[&apos;result&apos;][&apos;baseFeePerGas&apos;][-1], 16)
            max_gas_fee = 2 * basefee + priority_fee
        max_gas_fee = int(max_gas_fee, 16) if not isinstance(max_gas_fee, int) else max_gas_fee
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;maxPriorityFeePerGas&apos;: priority_fee, &apos;maxFeePerGas&apos;: max_gas_fee, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())

if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxx&apos; # 这里替换成自己的私钥
    account = web3.Account.from_key(privkey)
    COIN_DECIMALS = math.pow(10, 18) # 主币精度
    rpc = Rpc()
    value = 0.01 # 要存款的数量
    method = &apos;0xdeace8f5&apos; # 存款方法hash值
    uint_0 = &apos;000000000000000000000000000000000000000000000000000000000000e704&apos; # chainid
    addr_1 = account.address[2:].rjust(64, &apos;0&apos;) # recipient
    amount = int(value * COIN_DECIMALS)
    uint_2 = hex(amount)[2:].rjust(64, &apos;0&apos;) # amount
    uint_3 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos; # amountOutMin
    time_4 = hex(int(time.time() + 7 * 86400))[2:].rjust(64, &apos;0&apos;) # deadline
    addr_5 = &apos;00000000000000000000000081682250d4566b2986a2b33e23e7c52d401b7ab7&apos; # relayer
    uint_6 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos; # relayerFee
    data = method + uint_0 + addr_1 +uint_2 + uint_3 + time_4 + addr_5 + uint_6
    amount += (0.01 * COIN_DECIMALS)
    data = data.lower()
    gaslimit = 130000
    to = &apos;0xe85b69930fc6d59da385c7cc9e8ff03f8f0469ba&apos; # linea存款的合约地址
    to = web3.Web3.toChecksumAddress(to)
    res = rpc.transfer_eip1559(account, to, amount, gaslimit, data=data)
    print(res)
"><code><span class="hljs-string">"""
pip install web3==5.29.1
"""</span>
<span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, api=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.api = api
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_current_block</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取最新区块"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_blockNumber"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_block_detail</span>(<span class="hljs-params">self, number</span>):
        <span class="hljs-string">"""获取区块hash"""</span>
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(number, <span class="hljs-built_in">int</span>):
            number = <span class="hljs-built_in">hex</span>(number)
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBlockByNumber"</span>,<span class="hljs-string">"params"</span>:[number,<span class="hljs-literal">True</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gasprice"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_max_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""(base*2 + Priority) * gasLimit"""</span>
        res = self.get_fee_history()
        base = <span class="hljs-built_in">int</span>(res[<span class="hljs-string">'result'</span>][<span class="hljs-string">'baseFeePerGas'</span>][-<span class="hljs-number">1</span>], <span class="hljs-number">16</span>)
        res = self.get_max_PriorityFeePerGas()
        priority = <span class="hljs-built_in">int</span>(res[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        <span class="hljs-keyword">return</span> base * <span class="hljs-number">2</span> + priority

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_fee_history</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取历史gasfee"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_feeHistory"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-string">"0x1"</span>, <span class="hljs-string">"latest"</span>, []],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_max_PriorityFeePerGas</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取Priority"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_maxPriorityFeePerGas"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_limit</span>(<span class="hljs-params">self, from_, to, data</span>):
        <span class="hljs-string">"""call计算gaslimit"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_estimateGas"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"from"</span>: from_, <span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">call</span>(<span class="hljs-params">self, to, data</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_call"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}, <span class="hljs-string">"latest"</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()<span class="hljs-comment">#(int(res.json()['result'], 16)) / math.pow(10,18)</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer_eip1559</span>(<span class="hljs-params">self, account, to, amount, gaslimit=<span class="hljs-number">21000</span>, priority_fee=<span class="hljs-literal">None</span>, max_gas_fee=<span class="hljs-literal">None</span>, **kw</span>):
        <span class="hljs-string">"""eip 1559发送tx, 更节省gas"""</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> priority_fee:
            priority_fee = self.get_max_PriorityFeePerGas()[<span class="hljs-string">'result'</span>]
        priority_fee = <span class="hljs-built_in">int</span>(priority_fee, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(priority_fee, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> priority_fee
        <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> max_gas_fee:
            basefee = <span class="hljs-built_in">int</span>(self.get_fee_history()[<span class="hljs-string">'result'</span>][<span class="hljs-string">'baseFeePerGas'</span>][-<span class="hljs-number">1</span>], <span class="hljs-number">16</span>)
            max_gas_fee = <span class="hljs-number">2</span> * basefee + priority_fee
        max_gas_fee = <span class="hljs-built_in">int</span>(max_gas_fee, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(max_gas_fee, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> max_gas_fee
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'maxPriorityFeePerGas'</span>: priority_fee, <span class="hljs-string">'maxFeePerGas'</span>: max_gas_fee, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    account = web3.Account.from_key(privkey)
    COIN_DECIMALS = math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>) <span class="hljs-comment"># 主币精度</span>
    rpc = Rpc()
    value = <span class="hljs-number">0.01</span> <span class="hljs-comment"># 要存款的数量</span>
    method = <span class="hljs-string">'0xdeace8f5'</span> <span class="hljs-comment"># 存款方法hash值</span>
    uint_0 = <span class="hljs-string">'000000000000000000000000000000000000000000000000000000000000e704'</span> <span class="hljs-comment"># chainid</span>
    addr_1 = account.address[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>) <span class="hljs-comment"># recipient</span>
    amount = <span class="hljs-built_in">int</span>(value * COIN_DECIMALS)
    uint_2 = <span class="hljs-built_in">hex</span>(amount)[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>) <span class="hljs-comment"># amount</span>
    uint_3 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span> <span class="hljs-comment"># amountOutMin</span>
    time_4 = <span class="hljs-built_in">hex</span>(<span class="hljs-built_in">int</span>(time.time() + <span class="hljs-number">7</span> * <span class="hljs-number">86400</span>))[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>) <span class="hljs-comment"># deadline</span>
    addr_5 = <span class="hljs-string">'00000000000000000000000081682250d4566b2986a2b33e23e7c52d401b7ab7'</span> <span class="hljs-comment"># relayer</span>
    uint_6 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span> <span class="hljs-comment"># relayerFee</span>
    data = method + uint_0 + addr_1 +uint_2 + uint_3 + time_4 + addr_5 + uint_6
    amount += (<span class="hljs-number">0.01</span> * COIN_DECIMALS)
    data = data.lower()
    gaslimit = <span class="hljs-number">130000</span>
    to = <span class="hljs-string">'0xe85b69930fc6d59da385c7cc9e8ff03f8f0469ba'</span> <span class="hljs-comment"># linea存款的合约地址</span>
    to = web3.Web3.toChecksumAddress(to)
    res = rpc.transfer_eip1559(account, to, amount, gaslimit, data=data)
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>存款成功</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cace7bfe9998c1a41a7df3092799c1ad24b6a522d177cb046b93728ed2945340.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>代码已上传</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/linea" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/linea at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/linea&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/linea" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/linea at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div><p>2层上Uniswap的交互可以参考 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo/blob/main/scroll/uniswap.py">Scroll 的代码</a>， 改下rpc地址就行</p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/HM6b0DDRN6fz-_csavo2zG78fj0qe_OpTzZCb_G9wSk">arb-claim教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/fc1eab8e67335d822261be959dc249d55a52876dad0d7e7672203454c86b6bb6.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[python版本的arb空投领取demo]]></title>
            <link>https://paragraph.com/@junjie9021-3/python-arb-demo</link>
            <guid>sACETOymikZCzTK9N1so</guid>
            <pubDate>Mon, 20 Mar 2023 05:46:08 GMT</pubDate>
            <description><![CDATA[python版本的arb空投领取demoimport web3 import requests headers = { 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, api='https://arb1.arbitrum.io/rpc', chainid=42161, proxies=None, timeout=30): self.api = api self.chainid = chainid self.proxies = proxies self.timeout = timeout def get_current_block(self): """获取最新区块""" data = {"jso...]]></description>
            <content:encoded><![CDATA[<p>python版本的arb空投领取demo</p><pre data-type="codeBlock" text="import web3
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, api=&apos;https://arb1.arbitrum.io/rpc&apos;, chainid=42161, proxies=None, timeout=30):
        self.api = api
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_current_block(self):
        &quot;&quot;&quot;获取最新区块&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_blockNumber&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_block_detail(self, number):
        &quot;&quot;&quot;获取区块hash&quot;&quot;&quot;
        if isinstance(number, int):
            number = hex(number)
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBlockByNumber&quot;,&quot;params&quot;:[number,True],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gasprice&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_limit(self, to, data):
        &quot;&quot;&quot;call计算gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_estimateGas&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def call(self, to, data):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_call&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}, &quot;latest&quot;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()#(int(res.json()[&apos;result&apos;], 16)) / math.pow(10,18)

    def transfer(self, account, to, amount, gaslimit, **kw):
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())

def claim(privkey):
    # 领取
    rpc = Rpc()
    # https://arbiscan.io/address/0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9
    token = &apos;0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9&apos; # 领取合约地址
    data = &apos;0x4e71d92d&apos;
    account = web3.Account.from_key(privkey)
    to = web3.Web3.toChecksumAddress(token)
    res = rpc.transfer(account, to, 0, gaslimit=455210, data=data)
    return res

def collection(privkey, address):
    # 归集
    # https://arbiscan.io/token/0x912ce59144191c1204e64559fe8253a0e49e6548#balances
    rpc = Rpc()
    account = web3.Account.from_key(privkey)
    token = &apos;0x912ce59144191c1204e64559fe8253a0e49e6548&apos; # arb 代币地址
    # 1.查询地址余额
    call_data = &apos;0x70a08231&apos; + &apos;000000000000000000000000&apos; + account.address[2:]
    res = rpc.call(token, call_data)
    value = res[&apos;result&apos;]
    # 2.转账
    addr_1 = address.lower()[2:].rjust(64,&apos;0&apos;)
    unit_2 = value[2:].rjust(64,&apos;0&apos;)
    data = &apos;0xa9059cbb&apos; + addr_1 + unit_2
    to = web3.Web3.toChecksumAddress(token)
    res = rpc.transfer(account, to, 0, gaslimit=455210, data=data)
    return res

if __name__ == &apos;__main__&apos;:
    pk = &apos;xxxxxxx&apos; # 你的私钥
    # 领取
    res = claim(pk)
    print(res)
    # 归集
    address = &apos;&apos; # 你的交易所钱包Arb地址
    res = collection(pk, address)
    print(res)
"><code><span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, api=<span class="hljs-string">'https://arb1.arbitrum.io/rpc'</span>, chainid=<span class="hljs-number">42161</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.api = api
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_current_block</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取最新区块"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_blockNumber"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_block_detail</span>(<span class="hljs-params">self, number</span>):
        <span class="hljs-string">"""获取区块hash"""</span>
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(number, <span class="hljs-built_in">int</span>):
            number = <span class="hljs-built_in">hex</span>(number)
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBlockByNumber"</span>,<span class="hljs-string">"params"</span>:[number,<span class="hljs-literal">True</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gasprice"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_limit</span>(<span class="hljs-params">self, to, data</span>):
        <span class="hljs-string">"""call计算gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_estimateGas"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">call</span>(<span class="hljs-params">self, to, data</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_call"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}, <span class="hljs-string">"latest"</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.api, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()<span class="hljs-comment">#(int(res.json()['result'], 16)) / math.pow(10,18)</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())

<span class="hljs-keyword">def</span> <span class="hljs-title function_">claim</span>(<span class="hljs-params">privkey</span>):
    <span class="hljs-comment"># 领取</span>
    rpc = Rpc()
    <span class="hljs-comment"># https://arbiscan.io/address/0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9</span>
    token = <span class="hljs-string">'0x67a24CE4321aB3aF51c2D0a4801c3E111D88C9d9'</span> <span class="hljs-comment"># 领取合约地址</span>
    data = <span class="hljs-string">'0x4e71d92d'</span>
    account = web3.Account.from_key(privkey)
    to = web3.Web3.toChecksumAddress(token)
    res = rpc.transfer(account, to, <span class="hljs-number">0</span>, gaslimit=<span class="hljs-number">455210</span>, data=data)
    <span class="hljs-keyword">return</span> res

<span class="hljs-keyword">def</span> <span class="hljs-title function_">collection</span>(<span class="hljs-params">privkey, address</span>):
    <span class="hljs-comment"># 归集</span>
    <span class="hljs-comment"># https://arbiscan.io/token/0x912ce59144191c1204e64559fe8253a0e49e6548#balances</span>
    rpc = Rpc()
    account = web3.Account.from_key(privkey)
    token = <span class="hljs-string">'0x912ce59144191c1204e64559fe8253a0e49e6548'</span> <span class="hljs-comment"># arb 代币地址</span>
    <span class="hljs-comment"># 1.查询地址余额</span>
    call_data = <span class="hljs-string">'0x70a08231'</span> + <span class="hljs-string">'000000000000000000000000'</span> + account.address[<span class="hljs-number">2</span>:]
    res = rpc.call(token, call_data)
    value = res[<span class="hljs-string">'result'</span>]
    <span class="hljs-comment"># 2.转账</span>
    addr_1 = address.lower()[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>)
    unit_2 = value[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>)
    data = <span class="hljs-string">'0xa9059cbb'</span> + addr_1 + unit_2
    to = web3.Web3.toChecksumAddress(token)
    res = rpc.transfer(account, to, <span class="hljs-number">0</span>, gaslimit=<span class="hljs-number">455210</span>, data=data)
    <span class="hljs-keyword">return</span> res

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    pk = <span class="hljs-string">'xxxxxxx'</span> <span class="hljs-comment"># 你的私钥</span>
    <span class="hljs-comment"># 领取</span>
    res = claim(pk)
    <span class="hljs-built_in">print</span>(res)
    <span class="hljs-comment"># 归集</span>
    address = <span class="hljs-string">''</span> <span class="hljs-comment"># 你的交易所钱包Arb地址</span>
    res = collection(pk, address)
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>代码已上传</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/arb-claim" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/arb-claim at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/arb-claim&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/arb-claim" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/arb-claim at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">原理分析教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg">lifeform 的 free mint 代码交互排查思路</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o">如何通过 rpc协议来交互 Base的存款</a></p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
        </item>
        <item>
            <title><![CDATA[life free mint 代码交互的源码]]></title>
            <link>https://paragraph.com/@junjie9021-3/life-free-mint</link>
            <guid>ix7Wn5OdvcTRJwpWrO7I</guid>
            <pubDate>Mon, 13 Mar 2023 14:42:13 GMT</pubDate>
            <description><![CDATA[之前我们分享了思路，非常棒，已经有很多小伙伴按照思路已经跑起来了。 https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg 给大家分享下交互源码，注意代码中的参数设置自己的私钥设置邀请人的地址 +500分这个代码已上传simple-airdrop-demo/life at main · junjie9021/simple-airdrop-demoContribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.https://github.com原理分析教程lifeform 的 free mint 代码交互排查思路如何通过 rpc协议来交互 Base的存款往期代码交互教程scroll alpha test bridge代码交互aave gho稳定币项目代码交互教程base 存款代码交互教程sui mint nft ...]]></description>
            <content:encoded><![CDATA[<p>之前我们分享了思路，非常棒，已经有很多小伙伴按照思路已经跑起来了。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg</a></p><p>给大家分享下交互源码，注意代码中的参数</p><ul><li><p>设置自己的私钥</p></li><li><p>设置邀请人的地址 +500分这个</p></li></ul><p>代码已上传</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/life" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/life at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/life&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/life" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/life at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">原理分析教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/etJQ20zi8b3pK1m0GfvnH8cnxoc9ErVhGKLk3YtKTIg">lifeform 的 free mint 代码交互排查思路</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o">如何通过 rpc协议来交互 Base的存款</a></p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
        </item>
        <item>
            <title><![CDATA[lifeform 的 free mint 代码交互思路]]></title>
            <link>https://paragraph.com/@junjie9021-3/lifeform-free-mint</link>
            <guid>4ah9jb9HdQNWXob8Gq2I</guid>
            <pubDate>Thu, 09 Mar 2023 15:25:27 GMT</pubDate>
            <description><![CDATA[给大家分享下之前很火的 lifeform 的 free mint 代码交互思路，如何签名，如何找到数据，如何排查的；现在还能 mint 的抓包分析请跟我一样，浏览器打开 mint 网址后，打开你的F12，简单的抓个包；看我的设置，去除杂七杂八的请求钱包签名我们先用小狐狸跑一遍流程，连接钱包，提示签名。复制下签名信息，注意签名信息的内容，长这样的 &apos;address=你的钱包地址,chain_id=56&apos; 这里你要学会用 web3库 Account 来签名消息import web3 from eth_account.messages import encode_defunct privkey='xxxx' # 你的私钥 account = web3.Account.from_key(privkey) msg = 'address=%s,chain_id=56' % account.address signature = account.sign_message(encode_defunct(text=msg)).hex() 查找登陆接口拿到签名的数据后，我们需要找...]]></description>
            <content:encoded><![CDATA[<blockquote><p>给大家分享下之前很火的 lifeform 的 free mint 代码交互思路，如何签名，如何找到数据，如何排查的；现在还能 mint 的</p></blockquote><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/acfcef8d753a4236e7090fa3ad3bf6a4ec3dd2015f62c2499b727b92a2c1fb49.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">抓包分析</h3><p>请跟我一样，浏览器打开 mint 网址后，打开你的F12，简单的抓个包；看我的设置，去除杂七杂八的请求</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b5a0dd80db1c49c4cca98725303d2e75988b5d9ea6315f2941325823c23fb267.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">钱包签名</h3><p>我们先用小狐狸跑一遍流程，连接钱包，提示签名。复制下签名信息，注意签名信息的内容，长这样的 &apos;address=你的钱包地址,chain_id=56&apos; 这里你要学会用 web3库 Account 来签名消息</p><pre data-type="codeBlock" text="import web3
from eth_account.messages import encode_defunct

privkey=&apos;xxxx&apos; # 你的私钥
account = web3.Account.from_key(privkey)
msg = &apos;address=%s,chain_id=56&apos; % account.address
signature = account.sign_message(encode_defunct(text=msg)).hex()
"><code><span class="hljs-keyword">import</span> <span class="hljs-title">web3</span>
<span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-title">eth_account</span>.<span class="hljs-title">messages</span> <span class="hljs-title"><span class="hljs-keyword">import</span></span> <span class="hljs-title">encode_defunct</span>

<span class="hljs-title">privkey</span><span class="hljs-operator">=</span><span class="hljs-string">'xxxx'</span> # 你的私钥
<span class="hljs-title">account</span> <span class="hljs-operator">=</span> <span class="hljs-title">web3</span>.<span class="hljs-title">Account</span>.<span class="hljs-title">from_key</span>(<span class="hljs-title">privkey</span>)
<span class="hljs-title"><span class="hljs-built_in">msg</span></span> <span class="hljs-operator">=</span> <span class="hljs-string">'address=%s,chain_id=56'</span> <span class="hljs-operator">%</span> <span class="hljs-title">account</span>.<span class="hljs-title"><span class="hljs-keyword">address</span></span>
<span class="hljs-title">signature</span> <span class="hljs-operator">=</span> <span class="hljs-title">account</span>.<span class="hljs-title">sign_message</span>(<span class="hljs-title">encode_defunct</span>(<span class="hljs-title">text</span><span class="hljs-operator">=</span><span class="hljs-title"><span class="hljs-built_in">msg</span></span>)).<span class="hljs-title">hex</span>()
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">查找登陆接口</h3><p>拿到签名的数据后，我们需要找到请求的登陆接口，大致长这样。注意你的标头信息看到 请求网址 和 请求方法，并且打开旁边的载荷，载荷就是要传输的数据，有3个字段 address: 你的钱包地址 chain_id: bsc chainid sign: 刚才你用 web3 Account签名的消息</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3922505a53c62b540765bfd8c8e46dc2712bb98c52c91744a08d50ef54e857bd.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-accesstoken" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">获取 access_token</h3><p>通过预览，我们看到了请求返回的数据，我们就是需要返回的 access_token，这个数据需要加到后续请求的header里</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/81047ecc1ac1f65d6fed4d6b92230830b6c31866750107b1a336898b53de2d69.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-header-authorization-accesstoken" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">header 添加 authorization = access_token</h3><p>页面点击 mint 我们可以看看发生了哪些请求，找不一致，发现这个接口。看到接口里的header authorization 字段的值就是刚才通过登录接口拿到的access_token</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d26a6c3594a2da4ad86830c47002c2157ac1c6c00b2d6a68cdae346a8cef2743.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">查看再次签名的字段</h3><p>再次查看载荷，发现有3个字段 address: 你的钱包地址 affAddress: 邀请地址 它+500分 gender: female 固定参数</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/861199076a4fc7e995dc940d8b1a699d35c1a926a8dcb46bb4182ce7d946e6d7.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-tx-hash-inputdata" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">查看签名后返回的数据并与tx hash InputData对比</h3><p>再次查看预览，看到了这些数据，不着急，数据字段有点多，先把数据复制好。小狐狸确认 mint ，广播 tx 后，拿到 tx 的inputdata，我们再来对比，确认需要的参数</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/af393b60898ed1f69a3e2c4515c9be5dc9e2d708d36fa479a479064312e88f90.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/cd30a7238592df7b3be32bafd947b5b84b968e9dc08f2e5ccb0f05c2f9aa0dd4.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>通过对比，我们发现之前的接口里的</p><p>signCode = InputData [10]</p><p>wlSignature = InputData [13] [14]</p><p>dataSignature.signature = InputData [17] [18]</p><p>这样我们就拿到了 free mint 所需要的参数，InputData 其他的字段数据大家可自行分析下，通过与其 他 tx 对比；拼接成完整的数据后，再通过合约交互，就能实现代码的成功 mint 了；</p><h2 id="h-" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">总结</h2><ul><li><p>熟练钱包签名</p></li><li><p>善用抓包工具</p></li><li><p>细心排查数据</p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">原理分析教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o">如何通过 rpc协议来交互 Base的存款</a></p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/09a93d203c4db28e34d1e15f656e56398dd908fbdaf4a1b18e053c4f8f99d623.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[ Zksync 测试网络的存款代码交互教程]]></title>
            <link>https://paragraph.com/@junjie9021-3/zksync</link>
            <guid>EbGBmzxKryjQZa6r9yH7</guid>
            <pubDate>Thu, 09 Mar 2023 04:54:06 GMT</pubDate>
            <description><![CDATA[刚有粉丝私信我，跟着我们之前的demo，尝试在做zksync的交互，非常棒。不过没发出去，帮他看了下，主要是给的gaslimit太小 拿着之前的样例给了100000；咋们跟官方跨链桥给的一样，gaslimit给600000，没用完的会自动返回给你的import requests import web3 import math headers = { 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, rpc='https://rpc.ankr.com/eth_goerli', chainid=5, proxies=None, timeout=30): self.rpc = rpc self.cha...]]></description>
            <content:encoded><![CDATA[<p>刚有粉丝私信我，跟着我们之前的demo，尝试在做zksync的交互，非常棒。不过没发出去，帮他看了下，主要是给的gaslimit太小 拿着之前的样例给了100000；咋们跟官方跨链桥给的一样，gaslimit给600000，没用完的会自动返回给你的</p><pre data-type="codeBlock" text="import requests
import web3
import math
headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_current_block(self):
        &quot;&quot;&quot;获取最新区块&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_blockNumber&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_block_detail(self, number):
        &quot;&quot;&quot;获取区块hash&quot;&quot;&quot;
        if isinstance(number, int):
            number = hex(number)
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBlockByNumber&quot;,&quot;params&quot;:[number,True],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_limit(self, to, data):
        &quot;&quot;&quot;计算gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_estimateGas&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def call(self, to, data):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_call&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}, &quot;latest&quot;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()#(int(res.json()[&apos;result&apos;], 16)) / math.pow(10,18)

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())

if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxx&apos; # 这里替换成自己的私钥
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = 0.01 # 要存款的数量
    gaslimit = 600000 # gaslimit
    token = &apos;0x1908e2bf4a88f91e4ef0dc72f02b8ea36bea2319&apos; # zksync存款的合约地址
    method = &apos;0xeb672419&apos; # 存款方法hash值
    addr_0 = account.address[2:].rjust(64,&apos;0&apos;) # 地址格式处理
    amount = int(value * math.pow(10, 18)) # eth的主币精度是18位
    value = hex(amount) # value hex格式处理
    unit_1 = value[2:].rjust(64,&apos;0&apos;)
    bytes_2 = &apos;00000000000000000000000000000000000000000000000000000000000000e0&apos;
    unit_3 = &apos;0000000000000000000000000000000000000000000000000000000000989680&apos;
    unit_4 = &apos;0000000000000000000000000000000000000000000000000000000000000320&apos;
    bytes_5 = &apos;0000000000000000000000000000000000000000000000000000000000000100&apos;
    addr_6 = addr_0
    unit_7 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos;
    unit_8 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos;
    data = method + addr_0 + unit_1 + bytes_2 + unit_3 + unit_4 + bytes_5 + addr_6 + unit_7 + unit_8  # 拼接数据
    res = rpc.transfer(account, to=token, amount=amount, gaslimit=gaslimit, data=data) # 发送交易
    print(res)
"><code><span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_current_block</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取最新区块"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_blockNumber"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_block_detail</span>(<span class="hljs-params">self, number</span>):
        <span class="hljs-string">"""获取区块hash"""</span>
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(number, <span class="hljs-built_in">int</span>):
            number = <span class="hljs-built_in">hex</span>(number)
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBlockByNumber"</span>,<span class="hljs-string">"params"</span>:[number,<span class="hljs-literal">True</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_limit</span>(<span class="hljs-params">self, to, data</span>):
        <span class="hljs-string">"""计算gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_estimateGas"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">call</span>(<span class="hljs-params">self, to, data</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_call"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}, <span class="hljs-string">"latest"</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()<span class="hljs-comment">#(int(res.json()['result'], 16)) / math.pow(10,18)</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = <span class="hljs-number">0.01</span> <span class="hljs-comment"># 要存款的数量</span>
    gaslimit = <span class="hljs-number">600000</span> <span class="hljs-comment"># gaslimit</span>
    token = <span class="hljs-string">'0x1908e2bf4a88f91e4ef0dc72f02b8ea36bea2319'</span> <span class="hljs-comment"># zksync存款的合约地址</span>
    method = <span class="hljs-string">'0xeb672419'</span> <span class="hljs-comment"># 存款方法hash值</span>
    addr_0 = account.address[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>) <span class="hljs-comment"># 地址格式处理</span>
    amount = <span class="hljs-built_in">int</span>(value * math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>)) <span class="hljs-comment"># eth的主币精度是18位</span>
    value = <span class="hljs-built_in">hex</span>(amount) <span class="hljs-comment"># value hex格式处理</span>
    unit_1 = value[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>)
    bytes_2 = <span class="hljs-string">'00000000000000000000000000000000000000000000000000000000000000e0'</span>
    unit_3 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000989680'</span>
    unit_4 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000320'</span>
    bytes_5 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000100'</span>
    addr_6 = addr_0
    unit_7 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span>
    unit_8 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span>
    data = method + addr_0 + unit_1 + bytes_2 + unit_3 + unit_4 + bytes_5 + addr_6 + unit_7 + unit_8  <span class="hljs-comment"># 拼接数据</span>
    res = rpc.transfer(account, to=token, amount=amount, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>执行脚本后打印交易hash, 去浏览器查询状态</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e73d88e253c023f4a1ca4fb32148b928f997245438fef91f0320b5eac455aeba.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/">https://goerli.etherscan.io/</a></p><p>代码样例已上传:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo/tree/main/zksync">https://github.com/junjie9021/simple-demo/tree/main/zksync</a></p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">原理分析教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o">如何通过 rpc协议来交互 Base的存款</a></p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/e828fbdbd1b3fe24ce4667053ae2c8d04576927953989f99211d96ce6a4fbd0b.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[分享下Scroll合约交互的Key值如何得来的]]></title>
            <link>https://paragraph.com/@junjie9021-3/scroll-key</link>
            <guid>EV0kkHk04B4BZbma9v7o</guid>
            <pubDate>Wed, 08 Mar 2023 15:15:07 GMT</pubDate>
            <description><![CDATA[之前为大家分享了 scroll 存款代码交互教程，大家发现我的代码样例里有个key值，有点疑惑，这个值的计算我是怎么知道的。 讲真，先开始我也不知道，用小狐狸手动走了一遍流程发，马上我就写了代码模拟来测试下，去查 tx hash 发送状态有问题，Fail with error &apos;Insufficient msg.value&apos; 报这个错误。我不信邪，又执行了几遍，还是这个错误。这会就要停下了，好好看下成功的交易并做对比。存款失败的情况通过这两个对比成功的tx hash 和代码执行失败的tx hash 那就是在 value 这个字段有区别，可以看到成功的 value 0**.01000004 和 失败的 value 0.015 它们之间存在这个值的0.**00000004的差别。存款成功的，小狐狸跑的不要着急，再去看下合约地址，看看其他人的交易是不是也是这样。仔细看下图，发现没有，是不是有个相同点，目前这个key=0.0000008。那么在存款时就可以得到实际发送的 amount += key成功交易的hash分析马上再测试，发现新的tx 状态ok的，可以成功存款...]]></description>
            <content:encoded><![CDATA[<p>之前为大家分享了 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll 存款代码交互教程</a>，大家发现我的代码样例里有个key值，有点疑惑，这个值的计算我是怎么知道的。</p><p>讲真，先开始我也不知道，用小狐狸手动走了一遍流程发，马上我就写了代码模拟来测试下，去查 tx hash 发送状态有问题，<strong>Fail with error &apos;Insufficient msg.value&apos;</strong> 报这个错误。我不信邪，又执行了几遍，还是这个错误。这会就要停下了，好好看下成功的交易并做对比。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/bc4bd5e7cc21f451ac4f78004e876ecfd74234b0d3fea92a133787458b9344ca.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>通过这两个对比<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/tx/0x47cf0535cc5b1e791bd12fcb3e2016265efcdaad1b9e1ba78b512ff55d285d64">成功的tx hash</a> 和代码执行<a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/tx/0x441addf501d73a9c24828f9bff45a69616bec86a38a9b703f8b265afd56aba23">失败的tx hash</a> 那就是在 value 这个字段有区别，可以看到成功的 value 0**.<strong>01000004 和 失败的 value 0</strong>.<strong>015 它们之间存在这个值的0</strong>.**00000004的差别。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c2c871b38094c7fe7a68f26485ff1a011ad048a8b1d983df7a6ec5bdd762360d.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>不要着急，再去看下合约地址，看看其他人的交易是不是也是这样。仔细看下图，发现没有，是不是有个相同点，目前这个key=0.0000008。那么在存款时就可以得到实际发送的</p><p>amount += key</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3a13c4730b584a9c4d2f85114b20493ecb7bc190be01e89117bf1ef1a7262e99.png" alt="成功交易的hash分析" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">成功交易的hash分析</figcaption></figure><p>马上再测试，发现新的tx 状态ok的，可以成功存款了。</p><p>Input Data还需要在分析下吗？还想听。好吧 分析下吧，很简单，第一参数是amount，不加key的哈。第二个是固定参数（其他成功tx都是这个参数，直接上）</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/becda6fab2abbcbd3bbb173a78e73c2424926d965376f5d2a987b033de7cd195.png" alt="InputData分析" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">InputData分析</figcaption></figure><p><strong>课外题</strong>： 如果这个key又变了怎么办呢？有知道的吗？我批量交互不能总上浏览器看吧，看了再来改，感觉有点low。</p><h2 id="h-" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">总结</h2><ul><li><p>细心找失败tx和成功tx之间的不同</p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">原理分析教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/dashboard/edit/eLMoVNgxH-XZTCSQBdw41x_yDNlyxXy8DeWqGGbmz6o">如何通过 rpc协议来交互 Base的存款</a></p></li></ul><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/09a93d203c4db28e34d1e15f656e56398dd908fbdaf4a1b18e053c4f8f99d623.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[如何通过 rpc协议来交互 Base的存款]]></title>
            <link>https://paragraph.com/@junjie9021-3/rpc-base</link>
            <guid>QLRulW9on10kQqu24pkC</guid>
            <pubDate>Wed, 08 Mar 2023 03:13:20 GMT</pubDate>
            <description><![CDATA[跟大家分享一下通过rpc协议交互base网络的存款，我是如何分析并用代码实现的。 首先，我们先用跨链桥手动完整的跑一下交互流程。现在我要存0.01个eth。存款界面确认我们的存款，拿到返回的hash，打开浏览器。View交易已经打包上链，注意 这里点开Click to show more， 我们要找到Input Data字段交易详情重要: 大家做好笔记，做好理解，我们会对data 进行解读input dataMethodId - 函数做KECCAK256hash计算，然后取计算结果的前四个字节，也就是hash值的前八位，然后拼接0x，就是这个方法的ID.""" Function: depositTransaction(address _to,uint256 _value,uint64 _gasLimit,bool _isCreation,bytes _data) """ import sha3 def keccak256_hash(text): k = sha3.keccak_256() k.update(text.encode('utf-8')) return k.hexdig...]]></description>
            <content:encoded><![CDATA[<p>跟大家分享一下通过rpc协议交互base网络的存款，我是如何分析并用代码实现的。</p><p>首先，我们先用跨链桥手动完整的跑一下交互流程。现在我要存0.01个eth。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ed5e8f52a53fdd7eb317227f4672314fb71085b44ec8c80ce32133a951c131e8.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>确认我们的存款，拿到返回的hash，打开浏览器。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c75267e8b4e3952d6040c83ad37abd69018149c8d0cc8badceab7bd3d2fa1e46.png" alt="View" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">View</figcaption></figure><p>交易已经打包上链，<strong>注意</strong> 这里点开Click to show more， 我们要找到Input Data字段</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/855a833085fac34dc20ddc50f7b2632e16c6ef50a6b8bc6ac82d924b4bee7d20.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><strong>重要: 大家做好笔记，做好理解，我们会对data 进行解读</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a74712434d924477b4f0b10132d46f40e7fde74131b1922c2742e7809426d2dd.png" alt="input data" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">input data</figcaption></figure><p>MethodId - 函数做KECCAK256hash计算，然后取计算结果的前四个字节，也就是hash值的前八位，然后拼接0x，就是这个方法的ID.</p><pre data-type="codeBlock" text="&quot;&quot;&quot;
Function: depositTransaction(address _to,uint256 _value,uint64 _gasLimit,bool _isCreation,bytes _data)

&quot;&quot;&quot;
import sha3

def keccak256_hash(text):
    k = sha3.keccak_256()
    k.update(text.encode(&apos;utf-8&apos;))
    return k.hexdigest()

func = &quot;depositTransaction(address,uint256,uint64,bool,bytes)&quot;
print(&apos;0x&apos; + keccak256_hash(func)[:8])
"><code><span class="hljs-string">"""
Function: depositTransaction(address _to,uint256 _value,uint64 _gasLimit,bool _isCreation,bytes _data)

"""</span>
<span class="hljs-keyword">import</span> sha3

<span class="hljs-keyword">def</span> <span class="hljs-title function_">keccak256_hash</span>(<span class="hljs-params">text</span>):
    k = sha3.keccak_256()
    k.update(text.encode(<span class="hljs-string">'utf-8'</span>))
    <span class="hljs-keyword">return</span> k.hexdigest()

func = <span class="hljs-string">"depositTransaction(address,uint256,uint64,bool,bytes)"</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">'0x'</span> + keccak256_hash(func)[:<span class="hljs-number">8</span>])
</code></pre><p>[0]: 000000000000000000000000b0a25771c5f7aa7772d9f6ea048ba80124c12d89</p><p>其实是自己的钱包地址</p><pre data-type="codeBlock" text="address = &quot;0xa25771c5f7aa7772d9f6ea048ba80124c12d89&quot;
print(address[2:].rjust(64, &apos;0&apos;))
"><code><span class="hljs-keyword">address</span> <span class="hljs-operator">=</span> <span class="hljs-string">"0xa25771c5f7aa7772d9f6ea048ba80124c12d89"</span>
print(<span class="hljs-keyword">address</span>[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>))
</code></pre><p>[1]: 000000000000000000000000000000000000000000000000002386f26fc10000 存款的数量0.01 eth</p><pre data-type="codeBlock" text="import math

value = 0.01
amount = int(value * math.pow(10, 18)) # 注意 eth 主币的精度是18位
print(hex(amount)[2:].rjust(64, &apos;0&apos;))
"><code><span class="hljs-keyword">import</span> math

value = <span class="hljs-number">0.01</span>
amount = <span class="hljs-built_in">int</span>(value * math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>)) <span class="hljs-comment"># 注意 eth 主币的精度是18位</span>
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">hex</span>(amount)[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>))
</code></pre><p>[2]: 00000000000000000000000000000000000000000000000000000000000186a0 gaslimit, 在打包上链时候传入的gaslimit。一般可以通过小狐狸拿下或者看其他人的交易。或者通过 rpc method eth_estimateGas来查询(有的合约不支持)</p><pre data-type="codeBlock" text="import math

gaslimit = 100000
print(hex(gaslimit)[2:].rjust(64, &apos;0&apos;))
"><code><span class="hljs-keyword">import</span> math

gaslimit = <span class="hljs-number">100000</span>
<span class="hljs-built_in">print</span>(<span class="hljs-built_in">hex</span>(gaslimit)[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>, <span class="hljs-string">'0'</span>))
</code></pre><p>[3]: 0000000000000000000000000000000000000000000000000000000000000000 [4]: 00000000000000000000000000000000000000000000000000000000000000a0 [5]: 0000000000000000000000000000000000000000000000000000000000000000</p><p>这些可以理解为固定参数, 暂时不需要强行理解它们。</p><p>通过这6个数据分析，我们发现这个方法主要要于前3个数据的变量传入，地址 address, 数量 amount, gas gaslimit，剩下的参数都是固定值。组装好这些数据，我们就可以直接跟合约交互，要修改状态的这种交互，统一用 transfer 来交互，如果不只是查询代币余额这些不改变状态的可以用 eth_call 方法来交互。</p><p>以下为完整脚本</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0</a></p><h2 id="h-" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">总结</h2><ul><li><p>用好浏览器工具，浏览器已经扫好了块，并解析好了tx</p></li><li><p>多测多看，看看合约相同methodId的inputdata数据，找不同点</p></li><li><p>理解 rpc 协议的交互</p></li></ul><p>像浏览器一样的打印inputdata数据</p><pre data-type="codeBlock" text="data = &quot;0xe9e05c42000000000000000000000000b0a25771c5f7aa7772d9f6ea048ba80124c12d89000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000&quot; # 这里放入inputdata值, 推文限制长度了，所以自己改下
start = 10
print(&apos;MethodId:&apos; + data[:10])
for i in range(int(len(data[10:])/64)):
    msg = &apos;[%d]: %s&apos; % (i, data[start:start+64])
    print(msg)
    start += 64
"><code>data <span class="hljs-operator">=</span> <span class="hljs-string">"0xe9e05c42000000000000000000000000b0a25771c5f7aa7772d9f6ea048ba80124c12d89000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000"</span> # 这里放入inputdata值, 推文限制长度了，所以自己改下
start <span class="hljs-operator">=</span> <span class="hljs-number">10</span>
print(<span class="hljs-string">'MethodId:'</span> <span class="hljs-operator">+</span> data[:<span class="hljs-number">10</span>])
<span class="hljs-keyword">for</span> i in range(<span class="hljs-keyword">int</span>(len(data[<span class="hljs-number">10</span>:])<span class="hljs-operator">/</span><span class="hljs-number">64</span>)):
    <span class="hljs-built_in">msg</span> <span class="hljs-operator">=</span> <span class="hljs-string">'[%d]: %s'</span> <span class="hljs-operator">%</span> (i, data[start:start<span class="hljs-operator">+</span><span class="hljs-number">64</span>])
    print(<span class="hljs-built_in">msg</span>)
    start <span class="hljs-operator">+</span><span class="hljs-operator">=</span> <span class="hljs-number">64</span>
</code></pre><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">aave gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-airdrop-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/8d7299403c0ea564e3dd6c0336d716073a48b0b89bf5ae6ab08053bdfd525735.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[scroll uniswap swap代码样例]]></title>
            <link>https://paragraph.com/@junjie9021-3/scroll-uniswap-swap</link>
            <guid>cCZO6qx6Fh9v1VNl7bCB</guid>
            <pubDate>Mon, 06 Mar 2023 14:57:31 GMT</pubDate>
            <description><![CDATA[scroll alpha 网络的 uniswap 的交互，我这点了一会界面发现只能 只能 swap，添加池子的操作界面一直置灰没搞成。 直接上代码样例。import web3 import math import requests headers = { 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, rpc='https://rpc.ankr.com/eth_goerli', chainid=5, proxies=None, timeout=30): self.rpc = rpc self.chainid = chainid self.proxies = proxies self.timeo...]]></description>
            <content:encoded><![CDATA[<p>scroll alpha 网络的 uniswap 的交互，我这点了一会界面发现只能 只能 swap，添加池子的操作界面一直置灰没搞成。</p><p>直接上代码样例。</p><pre data-type="codeBlock" text="import web3
import math
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_current_block(self):
        &quot;&quot;&quot;获取最新区块&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_blockNumber&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_block_detail(self, number):
        &quot;&quot;&quot;获取区块hash&quot;&quot;&quot;
        if isinstance(number, int):
            number = hex(number)
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBlockByNumber&quot;,&quot;params&quot;:[number,True],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def call(self, to, data):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_call&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}, &quot;latest&quot;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()#(int(res.json()[&apos;result&apos;], 16)) / math.pow(10,18)

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxx&apos; # 这里替换成自己的私钥
    value = 0.015 # 要存款的数量
    account = web3.Account.from_key(privkey)
    BALANCE_PRECISION = math.pow(10, 18) # 主币精度，18位
    rpc = Rpc(&apos;https://alpha-rpc.scroll.io/l2&apos;, chainid=534353)
    value = int(value * BALANCE_PRECISION)
    gaslimit = 45004 # gaslimit
    to = &apos;0x5300000000000000000000000000000000000004&apos; # 交互的合约地址
    method = &apos;0xd0e30db0&apos; # swap方法hash值
    data = method
    res = rpc.transfer(account, to=to, amount=value, gaslimit=gaslimit, data=data) # 发送交易
    print(res)
"><code><span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_current_block</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取最新区块"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_blockNumber"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_block_detail</span>(<span class="hljs-params">self, number</span>):
        <span class="hljs-string">"""获取区块hash"""</span>
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(number, <span class="hljs-built_in">int</span>):
            number = <span class="hljs-built_in">hex</span>(number)
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBlockByNumber"</span>,<span class="hljs-string">"params"</span>:[number,<span class="hljs-literal">True</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">call</span>(<span class="hljs-params">self, to, data</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_call"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}, <span class="hljs-string">"latest"</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()<span class="hljs-comment">#(int(res.json()['result'], 16)) / math.pow(10,18)</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    value = <span class="hljs-number">0.015</span> <span class="hljs-comment"># 要存款的数量</span>
    account = web3.Account.from_key(privkey)
    BALANCE_PRECISION = math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>) <span class="hljs-comment"># 主币精度，18位</span>
    rpc = Rpc(<span class="hljs-string">'https://alpha-rpc.scroll.io/l2'</span>, chainid=<span class="hljs-number">534353</span>)
    value = <span class="hljs-built_in">int</span>(value * BALANCE_PRECISION)
    gaslimit = <span class="hljs-number">45004</span> <span class="hljs-comment"># gaslimit</span>
    to = <span class="hljs-string">'0x5300000000000000000000000000000000000004'</span> <span class="hljs-comment"># 交互的合约地址</span>
    method = <span class="hljs-string">'0xd0e30db0'</span> <span class="hljs-comment"># swap方法hash值</span>
    data = method
    res = rpc.transfer(account, to=to, amount=value, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>完成后在浏览器上查下hash</p><div data-type="embedly" src="https://blockscout.scroll.io/" data="{&quot;provider_url&quot;:&quot;https://scrollscan.com&quot;,&quot;description&quot;:&quot;Scrollscan allows you to explore and search the blockchain for transactions, addresses, tokens, prices and other activities taking place on Scroll Network&quot;,&quot;title&quot;:&quot;Scroll (ETH) Blockchain Explorer&quot;,&quot;author_name&quot;:&quot;scrollscan.com&quot;,&quot;url&quot;:&quot;https://scrollscan.com/&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/c6dc3fecdef65116f8093cfc447bdbd832b8e5f73d4317244de2fa3c38d6b4d4.jpg&quot;,&quot;thumbnail_width&quot;:1600,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Scroll Blockchain Explorer&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:800,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1600,&quot;height&quot;:800,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/c6dc3fecdef65116f8093cfc447bdbd832b8e5f73d4317244de2fa3c38d6b4d4.jpg&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/c6dc3fecdef65116f8093cfc447bdbd832b8e5f73d4317244de2fa3c38d6b4d4.jpg"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://blockscout.scroll.io/" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Scroll (ETH) Blockchain Explorer</h2><p>Scrollscan allows you to explore and search the blockchain for transactions, addresses, tokens, prices and other activities taking place on Scroll Network</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://scrollscan.com</span></div><img src="https://storage.googleapis.com/papyrus_images/c6dc3fecdef65116f8093cfc447bdbd832b8e5f73d4317244de2fa3c38d6b4d4.jpg"/></div></a></div></div><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">scroll alpha test bridge代码交互</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">Aave Gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">Coinbase L2 Base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">Sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/633e4a72d054d38b1ef9ff150e3c1487f8e741fb865be722399c263ed184d642.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Base交互工具使用教程]]></title>
            <link>https://paragraph.com/@junjie9021-3/base</link>
            <guid>OvvcnZPyYp8U6CQVmffb</guid>
            <pubDate>Mon, 06 Mar 2023 03:46:20 GMT</pubDate>
            <description><![CDATA[Coinbase L2 Base网络交互工具支持功能查询存款取款mint nft认准唯一下载链接: https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1目前暂时提供win系统的版本为安全考虑，建议大家不要用本地电脑来运行，大家也应该要有这样的意识，防止软件钓鱼，病毒。在这里，建议大家可以上腾讯云购买个香港竞价实例的机器，机器的配置价格在0.13¥/H 竞价室例→中国香港→标准型S5 2C2G→Windows→64位 Windows 2022数据中心 中文版选择竞价实例2C2G 64位 Windows 2022数据中心 中文版按流量计费，带宽拉满100M按流量计费，拉满带宽输入密码确认密码通过电脑自带的远程服务器或者通过腾讯云的登录来上机器通过Edge 浏览器下载工具，记得还要下载解压工具，推荐用.7z https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1 解压工具进入目录找到app.exe, 双击运行。查询功能 输入地址，...]]></description>
            <content:encoded><![CDATA[<h2 id="h-coinbase-l2-base" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Coinbase L2 Base网络交互工具支持功能</h2><ul><li><p>查询</p></li><li><p>存款</p></li><li><p>取款</p></li><li><p>mint nft</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/636ce00a901f2671c70b5d1d6871dd6af3f6833462a91ffb3d1f7eb37e148793.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><strong>认准唯一下载链接</strong>:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1">https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1</a></p><h3 id="h-win" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">目前暂时提供win系统的版本</h3><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/aa053f4201bc91d02d7320edd8f7b9bc4bd1e06fd29f856b6e7f476cb025d058.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><strong>为安全考虑</strong>，建议大家不要用本地电脑来运行，大家也应该要有这样的意识，防止软件钓鱼，病毒。在这里，建议大家可以上腾讯云购买个香港竞价实例的机器，机器的配置价格在0.13¥/H</p><p>竞价室例→中国香港→标准型S5 2C2G→Windows→64位 Windows 2022数据中心 中文版</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/23a8adda676881a0796b28d3e7052cb3b8d04d7766b16357c2e7ca277632968b.png" alt="选择竞价实例" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">选择竞价实例</figcaption></figure><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b4302292eabfadd5fa5113449b89a93f5171c818f3e46aa422065078ca077af0.png" alt="2C2G 64位 Windows 2022数据中心 中文版" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">2C2G 64位 Windows 2022数据中心 中文版</figcaption></figure><p>按流量计费，带宽拉满100M</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4d32e3dc41d04d1bfd558977e239caa51ca067d8be9a9edca97238af53115d98.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>输入密码</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/8624073fc6e474179dfe18f6dd8bf241cc614abc6ff0f7046d84d78bf0c4b896.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>通过电脑自带的远程服务器或者通过腾讯云的登录来上机器</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/ef20f0a53f8488dc5ff138407a7d016118dce271e022d14c3d5b48679e91c541.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>通过Edge 浏览器下载工具，<strong>记得还要下载解压工具，推荐用.7z</strong></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1">https://github.com/junjie9021/simple-demo/releases/tag/base-v0.0.1</a></p><p>解压工具</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2fe36800b41550c3fb1407a224c23babf3efb382fa0c6bf5fa37e8153d5f66dd.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>进入目录找到app.exe, 双击运行。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/07c00c6cb88172ad993afa2e799d1b7d80f007a4631b32c8473c60a3296fa519.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><strong>查询功能</strong></p><p>输入地址，获得L1与L2 余额，日志可以通过鼠标点击再Ctrl+C来复制内容。</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3c5316457a0de2b257b9fbf00b6a946aad78580588ce07f30f598770533545b2.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><strong>存款功能</strong></p><p>需要输入私钥，建议用<strong>小号或新生成的地址私钥</strong>来测试，注意存款额度 是在最大-最小之间随机取值</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/636ce00a901f2671c70b5d1d6871dd6af3f6833462a91ffb3d1f7eb37e148793.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><strong>设置</strong></p><p>建议用默认值，主要设置L1 rpc与L2 rpc。如果你觉得网络不稳定可以在chainlist.org上查询最优rpc链接。<strong>gaslimit不要动</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/4e46ce0e3e69656b523e091c8fb21de5173e831f53445fad5b82da0cf785604c.png" alt="基础配置" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">基础配置</figcaption></figure><h2 id="h-" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">其他事项</h2><p><strong>提款功能</strong>暂时实现了L2上的发起，L1上还需要2次确认才能完全提款。你可以通过官方桥看到提款的状态</p><div data-type="embedly" src="https://bridge.base.org/transactions" data="{&quot;provider_url&quot;:&quot;https://docs.base.org&quot;,&quot;description&quot;:&quot;Documentation for bridging assets to Base. This page covers how to bridge ETH and ERC-20s between Ethereum (L1) and Base along with essential information.&quot;,&quot;title&quot;:&quot;Bridges - Base Documentation&quot;,&quot;mean_alpha&quot;:254.698015873,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://docs.base.org/base-chain/network-information/bridges-mainnet&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/c579bd940abb357c993cb554eb2ff1cb88ecfc023f8ddc748f4d8225801994ed.png&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Base Documentation&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:630,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:630,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/c579bd940abb357c993cb554eb2ff1cb88ecfc023f8ddc748f4d8225801994ed.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/c579bd940abb357c993cb554eb2ff1cb88ecfc023f8ddc748f4d8225801994ed.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://bridge.base.org/transactions" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Bridges - Base Documentation</h2><p>Documentation for bridging assets to Base. This page covers how to bridge ETH and ERC-20s between Ethereum (L1) and Base along with essential information.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://docs.base.org</span></div><img src="https://storage.googleapis.com/papyrus_images/c579bd940abb357c993cb554eb2ff1cb88ecfc023f8ddc748f4d8225801994ed.png"/></div></a></div></div><p><strong>mint nft功能</strong>暂时实现了 mint cat功能，燃烧nft还未添加，可通过查询</p><div data-type="embedly" src="https://catattacknft.vercel.app/" data="{&quot;url&quot;:&quot;https://catattacknft.vercel.app&quot;,&quot;provider_url&quot;:&quot;https://catattacknft.vercel.app&quot;,&quot;provider_name&quot;:&quot;Vercel&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;type&quot;:&quot;link&quot;}" format="small"></div><p>再次提醒各位为安全考虑，切勿本地使用。</p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p>scroll alpha test bridge代码交互[</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/O04bGQYMc6H7fhYiCBdbpOAJl_ygG50ehW6LQRsRsvg</a></p><p>]</p></li><li><p>Aave Gho稳定币项目代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc</a></p></li><li><p>Coinbase L2 Base 存款代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0</a></p></li><li><p>Sui mint nft 代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/74cb9d5cb8e099f6c4e667acadd3a8296feb8fdca4d9ce6d05a982b6f971e687.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[scroll alpha test bridge代码交互]]></title>
            <link>https://paragraph.com/@junjie9021-3/scroll-alpha-test-bridge</link>
            <guid>1izAxVudpzTxVOzqHkTy</guid>
            <pubDate>Fri, 03 Mar 2023 07:31:03 GMT</pubDate>
            <description><![CDATA[scroll alpha 网络的交互，目前只有bridge，暂时还没看到其他应用。大家要是有找到L2层上部署的应用，可以发下哈。python3 代码样例安装依赖注意privkey 改成要交互的私钥发送后去浏览器上查下tx状态，半天没返回的，就要换下rpc节点，可在 chainlist查看有个key值暂时不要动， 要是tx 状态失败的，还得去合约上查下最新的import web3 import math import requests headers = { 'content-type': 'application/json', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, rpc='https://rpc.ankr.com/eth_goerli', chaini...]]></description>
            <content:encoded><![CDATA[<p>scroll alpha 网络的交互，目前只有bridge，暂时还没看到其他应用。大家要是有找到L2层上部署的应用，可以发下哈。</p><h2 id="h-python3" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">python3 代码样例</h2><p>安装依赖</p><pre data-type="codeBlock" text="pip install web3
"><code></code></pre><p><strong>注意</strong></p><ul><li><p>privkey 改成要交互的私钥</p></li><li><p>发送后去浏览器上查下tx状态，半天没返回的，就要换下rpc节点，可在 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://chainlist.org">chainlist</a>查看</p></li><li><p>有个key值暂时不要动， 要是tx 状态失败的，还得去合约上查下最新的</p></li></ul><pre data-type="codeBlock" text="import web3
import math
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_current_block(self):
        &quot;&quot;&quot;获取最新区块&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_blockNumber&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_block_detail(self, number):
        &quot;&quot;&quot;获取区块hash&quot;&quot;&quot;
        if isinstance(number, int):
            number = hex(number)
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBlockByNumber&quot;,&quot;params&quot;:[number,True],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def call(self, to, data):
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_call&quot;,&quot;params&quot;:[{&quot;to&quot;: to, &quot;data&quot;: data}, &quot;latest&quot;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()#(int(res.json()[&apos;result&apos;], 16)) / math.pow(10,18)

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxxxxxxx&apos; # 这里替换成自己的私钥
    value = 0.1 # 要存款的数量
    account = web3.Account.from_key(privkey)
    BALANCE_PRECISION = math.pow(10, 18) # 主币精度，18位
    rpc = Rpc(&apos;https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161&apos;)
    value = int(value * BALANCE_PRECISION)
    gaslimit = 280000 # gaslimit
    to = &apos;0xe5e30e7c24e4dfcb281a682562e53154c15d3332&apos; # 交互的合约地址
    method = &apos;0x9f8420b3&apos; # 存款方法hash值
    key = 0.0000000625 # key值有可能经常改，昨晚还是0.00000004的
    amount = value + key * BALANCE_PRECISION # 计算要发送的amount
    data = &apos;0x9f8420b3&apos; + hex(value)[2:].rjust(64,&apos;0&apos;) + &apos;0000000000000000000000000000000000000000000000000000000000009c40&apos; # 拼接数据
    res = rpc.transfer(account, to=to, amount=amount, gaslimit=gaslimit, data=data) # 发送交易
    print(res)
"><code><span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_current_block</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取最新区块"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_blockNumber"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_block_detail</span>(<span class="hljs-params">self, number</span>):
        <span class="hljs-string">"""获取区块hash"""</span>
        <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(number, <span class="hljs-built_in">int</span>):
            number = <span class="hljs-built_in">hex</span>(number)
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBlockByNumber"</span>,<span class="hljs-string">"params"</span>:[number,<span class="hljs-literal">True</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">call</span>(<span class="hljs-params">self, to, data</span>):
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_call"</span>,<span class="hljs-string">"params"</span>:[{<span class="hljs-string">"to"</span>: to, <span class="hljs-string">"data"</span>: data}, <span class="hljs-string">"latest"</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()<span class="hljs-comment">#(int(res.json()['result'], 16)) / math.pow(10,18)</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    value = <span class="hljs-number">0.1</span> <span class="hljs-comment"># 要存款的数量</span>
    account = web3.Account.from_key(privkey)
    BALANCE_PRECISION = math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>) <span class="hljs-comment"># 主币精度，18位</span>
    rpc = Rpc(<span class="hljs-string">'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161'</span>)
    value = <span class="hljs-built_in">int</span>(value * BALANCE_PRECISION)
    gaslimit = <span class="hljs-number">280000</span> <span class="hljs-comment"># gaslimit</span>
    to = <span class="hljs-string">'0xe5e30e7c24e4dfcb281a682562e53154c15d3332'</span> <span class="hljs-comment"># 交互的合约地址</span>
    method = <span class="hljs-string">'0x9f8420b3'</span> <span class="hljs-comment"># 存款方法hash值</span>
    key = <span class="hljs-number">0.0000000625</span> <span class="hljs-comment"># key值有可能经常改，昨晚还是0.00000004的</span>
    amount = value + key * BALANCE_PRECISION <span class="hljs-comment"># 计算要发送的amount</span>
    data = <span class="hljs-string">'0x9f8420b3'</span> + <span class="hljs-built_in">hex</span>(value)[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>) + <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000009c40'</span> <span class="hljs-comment"># 拼接数据</span>
    res = rpc.transfer(account, to=to, amount=amount, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>执行脚本后打印交易hash, 去浏览器查询状态</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e609fd52b13a823354a744e9beabf1c7543815b269fc8bccc000e9204f5452f5.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/">https://goerli.etherscan.io/</a></p><p>代码样例已上传:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo">https://github.com/junjie9021/simple-demo</a></p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">Aave Gho稳定币项目代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">Coinbase L2 Base 存款代码交互教程</a></p></li><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XHRTueAW7jk13TOHVdPchzkM38PnDxidsJqY2TCnqTQ">Sui mint nft 代码交互教程</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/4009ccf599847f9a636d45f30f8481cfe8f89f916641844cd3f36abc85165fe4.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Sui mint nft 代码交互样例]]></title>
            <link>https://paragraph.com/@junjie9021-3/sui-mint-nft</link>
            <guid>QNztUds0x5BkZXdg8AXd</guid>
            <pubDate>Thu, 02 Mar 2023 03:15:24 GMT</pubDate>
            <description><![CDATA[对接上篇的 sui rpc 调用样例，这次把 devnet 的 mint nft 样例补上。 https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XU7k1qJrJR23R-NCoYp2qy20ttqzJQKXPHZKOQq6DK8 python3 代码样例# 记得先安装依赖 pip install bip_utils """ pip install bip_utils """ import nacl import base64 import hashlib import requests import bip_utils from rpc import Rpc headers = { 'content-type': 'application/json', } class Account: def __init__(self, mnemonic: str, derivation_path="m/44'/784'/0'/0'/0'"): self.mnemonic = mnemonic self.derivat...]]></description>
            <content:encoded><![CDATA[<p>对接上篇的 sui rpc 调用样例，这次把 devnet 的 mint nft 样例补上。</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XU7k1qJrJR23R-NCoYp2qy20ttqzJQKXPHZKOQq6DK8">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/XU7k1qJrJR23R-NCoYp2qy20ttqzJQKXPHZKOQq6DK8</a></p><p>python3 代码样例</p><pre data-type="codeBlock" text="# 记得先安装依赖
pip install bip_utils
"><code><span class="hljs-comment"># 记得先安装依赖</span>
pip install bip_utils
</code></pre><pre data-type="codeBlock" text="&quot;&quot;&quot;
pip install bip_utils
&quot;&quot;&quot;

import nacl
import base64
import hashlib
import requests
import bip_utils
from rpc import Rpc

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    }

class Account:
    def __init__(self,  mnemonic: str, derivation_path=&quot;m/44&apos;/784&apos;/0&apos;/0&apos;/0&apos;&quot;):
        self.mnemonic = mnemonic
        self.derivation_path = derivation_path
        self.bip39_seed = bip_utils.Bip39SeedGenerator(self.mnemonic).Generate()  # or = bip39.phrase_to_seed(mnemonic)
        self.bip32_ctx = bip_utils.Bip32Slip10Ed25519.FromSeed(self.bip39_seed)
        self.bip32_der_ctx = self.bip32_ctx.DerivePath(derivation_path)
        self.private_key: bytes = self.bip32_der_ctx.PrivateKey().Raw().ToBytes()
        self.public_key: bytes = self.bip32_der_ctx.PublicKey().RawCompressed().ToBytes()
        self.full_private_key = self.private_key[:32] + self.public_key[1:]
        self.address = self.get_address()

    @staticmethod
    def generate():
        return Account(mnemonic=bip_utils.Bip39MnemonicGenerator().FromWordsNumber(bip_utils.Bip39WordsNum.WORDS_NUM_12).ToStr())

    def get_address(self) -&gt; str:
        return &quot;0x&quot; + hashlib.sha3_256(self.bip32_der_ctx.PublicKey().RawCompressed().ToBytes()).digest().hex()[:40]

    def sign_data(self, data: bytes) -&gt; bytes:
        return nacl.signing.SigningKey(self.private_key).sign(data)[:64]  # Todo: support secp256k1 key and signature

    def get_public_key_as_b64_string(self) -&gt; str:
        return base64.b64encode(self.public_key[1:]).decode()
    
if __name__ == &apos;__main__&apos;:
    rpc = Rpc(&apos;https://fullnode.devnet.sui.io&apos;)
    account = Account.generate() # 生成一个地址
    account = Account(&apos;pilot fish popular tuna energy zoo initial vivid gym win gain author&apos;)
    print(account.mnemonic, account.address) # 打印私钥和地址
    faucet_url = &apos;https://faucet.devnet.sui.io/gas&apos;
    data = {&quot;FixedAmountRequest&quot;:{&quot;recipient&quot;: account.address}}
    res = requests.post(faucet_url, json=data,  headers=headers, verify=False) # 领水
    print(res.json()) # 打印输出
    # mint nft
    args = [&quot;Example NFT&quot;, &quot;An NFT created by Sui Wallet&quot;, &quot;ipfs://QmZPWWy5Si54R3d26toaqRiqvCH7HkGdXkxwUgCm2oKKM2?filename=img-sq-01.png&quot;] # mint nft的参数
    res = rpc.move_call(account.address, &apos;0x2&apos;, &apos;devnet_nft&apos;, &apos;mint&apos;, args, gas_budget=2000) # 与合约交互获取返回的txBytes
    tx = res[&apos;result&apos;][&apos;txBytes&apos;]
    res = rpc.sendtx(tx, account) # 广播交易
    print(res) # 打印交易hash
    
"><code><span class="hljs-string">"""
pip install bip_utils
"""</span>

<span class="hljs-keyword">import</span> nacl
<span class="hljs-keyword">import</span> base64
<span class="hljs-keyword">import</span> hashlib
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> bip_utils
<span class="hljs-keyword">from</span> rpc <span class="hljs-keyword">import</span> Rpc

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Account</span>:
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self,  mnemonic: <span class="hljs-built_in">str</span>, derivation_path=<span class="hljs-string">"m/44'/784'/0'/0'/0'"</span></span>):
        self.mnemonic = mnemonic
        self.derivation_path = derivation_path
        self.bip39_seed = bip_utils.Bip39SeedGenerator(self.mnemonic).Generate()  <span class="hljs-comment"># or = bip39.phrase_to_seed(mnemonic)</span>
        self.bip32_ctx = bip_utils.Bip32Slip10Ed25519.FromSeed(self.bip39_seed)
        self.bip32_der_ctx = self.bip32_ctx.DerivePath(derivation_path)
        self.private_key: <span class="hljs-built_in">bytes</span> = self.bip32_der_ctx.PrivateKey().Raw().ToBytes()
        self.public_key: <span class="hljs-built_in">bytes</span> = self.bip32_der_ctx.PublicKey().RawCompressed().ToBytes()
        self.full_private_key = self.private_key[:<span class="hljs-number">32</span>] + self.public_key[<span class="hljs-number">1</span>:]
        self.address = self.get_address()

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">generate</span>():
        <span class="hljs-keyword">return</span> Account(mnemonic=bip_utils.Bip39MnemonicGenerator().FromWordsNumber(bip_utils.Bip39WordsNum.WORDS_NUM_12).ToStr())

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_address</span>(<span class="hljs-params">self</span>) -> <span class="hljs-built_in">str</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">"0x"</span> + hashlib.sha3_256(self.bip32_der_ctx.PublicKey().RawCompressed().ToBytes()).digest().<span class="hljs-built_in">hex</span>()[:<span class="hljs-number">40</span>]

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">sign_data</span>(<span class="hljs-params">self, data: <span class="hljs-built_in">bytes</span></span>) -> <span class="hljs-built_in">bytes</span>:
        <span class="hljs-keyword">return</span> nacl.signing.SigningKey(self.private_key).sign(data)[:<span class="hljs-number">64</span>]  <span class="hljs-comment"># Todo: support secp256k1 key and signature</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_public_key_as_b64_string</span>(<span class="hljs-params">self</span>) -> <span class="hljs-built_in">str</span>:
        <span class="hljs-keyword">return</span> base64.b64encode(self.public_key[<span class="hljs-number">1</span>:]).decode()
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    rpc = Rpc(<span class="hljs-string">'https://fullnode.devnet.sui.io'</span>)
    account = Account.generate() <span class="hljs-comment"># 生成一个地址</span>
    account = Account(<span class="hljs-string">'pilot fish popular tuna energy zoo initial vivid gym win gain author'</span>)
    <span class="hljs-built_in">print</span>(account.mnemonic, account.address) <span class="hljs-comment"># 打印私钥和地址</span>
    faucet_url = <span class="hljs-string">'https://faucet.devnet.sui.io/gas'</span>
    data = {<span class="hljs-string">"FixedAmountRequest"</span>:{<span class="hljs-string">"recipient"</span>: account.address}}
    res = requests.post(faucet_url, json=data,  headers=headers, verify=<span class="hljs-literal">False</span>) <span class="hljs-comment"># 领水</span>
    <span class="hljs-built_in">print</span>(res.json()) <span class="hljs-comment"># 打印输出</span>
    <span class="hljs-comment"># mint nft</span>
    args = [<span class="hljs-string">"Example NFT"</span>, <span class="hljs-string">"An NFT created by Sui Wallet"</span>, <span class="hljs-string">"ipfs://QmZPWWy5Si54R3d26toaqRiqvCH7HkGdXkxwUgCm2oKKM2?filename=img-sq-01.png"</span>] <span class="hljs-comment"># mint nft的参数</span>
    res = rpc.move_call(account.address, <span class="hljs-string">'0x2'</span>, <span class="hljs-string">'devnet_nft'</span>, <span class="hljs-string">'mint'</span>, args, gas_budget=<span class="hljs-number">2000</span>) <span class="hljs-comment"># 与合约交互获取返回的txBytes</span>
    tx = res[<span class="hljs-string">'result'</span>][<span class="hljs-string">'txBytes'</span>]
    res = rpc.sendtx(tx, account) <span class="hljs-comment"># 广播交易</span>
    <span class="hljs-built_in">print</span>(res) <span class="hljs-comment"># 打印交易hash</span>
    
</code></pre><p>通过浏览器看到，地址已经领水并成功 mint nft</p><div data-type="embedly" src="https://explorer.sui.io/address/0x87f85444c31066b509b414c828e2e65a2e77d85d" data="{&quot;provider_url&quot;:&quot;https://suiexplorer.com&quot;,&quot;description&quot;:&quot;Explore transactions, objects, etc. of Sui network&quot;,&quot;title&quot;:&quot;Sui Explorer&quot;,&quot;url&quot;:&quot;https://suiexplorer.com/address/0x87f85444c31066b509b414c828e2e65a2e77d85d&quot;,&quot;mean_alpha&quot;:115.5,&quot;thumbnail_width&quot;:2400,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/4e7426e1f647f08376e5f233121ac7f0ffef795258f1d0fea65e9f2846dbd994.png&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Suiexplorer&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:1350,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:2400,&quot;height&quot;:1350,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/4e7426e1f647f08376e5f233121ac7f0ffef795258f1d0fea65e9f2846dbd994.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/4e7426e1f647f08376e5f233121ac7f0ffef795258f1d0fea65e9f2846dbd994.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://explorer.sui.io/address/0x87f85444c31066b509b414c828e2e65a2e77d85d" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Sui Explorer</h2><p>Explore transactions, objects, etc. of Sui network</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://suiexplorer.com</span></div><img src="https://storage.googleapis.com/papyrus_images/4e7426e1f647f08376e5f233121ac7f0ffef795258f1d0fea65e9f2846dbd994.png"/></div></a></div></div><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0456dd6a8c17df4aabac29f949c4389d5f21b939e69497acb913a10bd6e93f95.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p><strong>开发网络和测试网络 mint nft 的代码都一样的</strong></p><p>代码已上传:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo/tree/main/Sui">https://github.com/junjie9021/simple-demo/tree/main/Sui</a></p><h3 id="h-" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">往期代码交互教程</h3><ul><li><p>Aave Gho稳定币项目代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/tdjYv4dEnsQry_U44kj0sbDa5htuRBYHpUf45w8v-qc</a></p></li><li><p>Coinbase L2 Base 存款代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/HhnUs4fDOFgfzjC6batf4QPqQH2xlYcHJlJ89toGhlc">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/HhnUs4fDOFgfzjC6batf4QPqQH2xlYcHJlJ89toGhlc</a></p></li><li><p>Coinbase L2 Base 主网纪念nft mint 代码交互教程</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/HhnUs4fDOFgfzjC6batf4QPqQH2xlYcHJlJ89toGhlc">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/HhnUs4fDOFgfzjC6batf4QPqQH2xlYcHJlJ89toGhlc</a></p></li></ul><p>我的 <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://twitter.com/junjie9021">推特</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://lenster.xyz/u/0x049">Lens</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://link3.to/junjie9021">Link3</a> <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/junjie9021/simple-demo">Github</a></p>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/38cb41c1c040ee12a123c722c6a3c2c30915e9f7ede82593cd5c439b8b650430.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Sui rpc协议代码示例]]></title>
            <link>https://paragraph.com/@junjie9021-3/sui-rpc</link>
            <guid>V55pSsMigmrei30POfR4</guid>
            <pubDate>Tue, 28 Feb 2023 01:52:06 GMT</pubDate>
            <description><![CDATA[Sui已经完成wave1和wave2阶段，预计后面还有2阶段。现给大家提供 Rpc 协议 Python3 调用代码样例。import uuid import json import base64 import urllib3 import requests from typing import List urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) headers = { 'content-type': 'application/json', 'accept-encoding': 'gzip, deflate, br', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } SUI_COIN_TYPE = "0x2::coin::Coin&#x3C;0x2::sui::SUI...]]></description>
            <content:encoded><![CDATA[<p>Sui已经完成wave1和wave2阶段，预计后面还有2阶段。现给大家提供 Rpc 协议 Python3 调用代码样例。</p><pre data-type="codeBlock" text="import uuid
import json
import base64
import urllib3
import requests
from typing import List
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;accept-encoding&apos;: &apos;gzip, deflate, br&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

SUI_COIN_TYPE = &quot;0x2::coin::Coin&lt;0x2::sui::SUI&gt;&quot;


class Rpc:
    def __init__(self, api=&apos;https://fullnode.testnet.sui.io/&apos;, proxies=None):
        self.api = api
        self.proxies = proxies

    def get_objects(self, address):
        &quot;&quot;&quot;获取地址拥有的objs
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_getObjectsOwnedByAddress&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [address],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()
        
    def get_object(self, obj_id):
        &quot;&quot;&quot;返回指定对象的对象信息;
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_getObject&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [obj_id],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def get_transaction(self, tx):
        &quot;&quot;&quot;获取交易详情
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_getTransaction&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [tx],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def transfer_sui(self, from_, object_id, to, amount, gas=1000,):
        &quot;&quot;&quot;创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_transferSui&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [from_, object_id, gas, to, int(amount)],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def pay_sui(self, from_, objs, to, amount, gas=300):
        &quot;&quot;&quot;创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_paySui&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [from_, objs, [to], amount, gas],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def pay_all_sui(self, from_, objs, to, gas=1000):
        &quot;&quot;&quot;创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_payAllSui&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [from_, objs, to, gas],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def transfer(self, from_, to, amount):
        objs = self.get_objects(from_)
        amount = int(amount)
        sui_objs = [i[&apos;objectId&apos;] for i in objs[&apos;result&apos;] if i[&apos;type&apos;] == SUI_COIN_TYPE]
        balance = 0
        pay_objs = []
        for i in sui_objs:
            obj = self.get_object(i)
            if int(obj[&apos;result&apos;][&apos;details&apos;][&apos;data&apos;][&apos;fields&apos;][&apos;balance&apos;]) &gt; amount:
                res = self.pay_sui(from_, [i], to, [amount])
                return res
            balance += int(obj[&apos;result&apos;][&apos;details&apos;][&apos;data&apos;][&apos;fields&apos;][&apos;balance&apos;])
            pay_objs.append(i)
            if balance &gt;= amount:
                res = self.pay_sui(from_, pay_objs, to, [amount])
                return res

    def merge_coin(self, address, primary_obj_id, merge_obj_id, gas=1000, gas_object_id=None):
        &quot;&quot;&quot;合并硬币;
        &quot;&quot;&quot;
        gas_object_id = primary_obj_id
        data = {&quot;method&quot;: &quot;sui_mergeCoins&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [address, primary_obj_id, merge_obj_id, gas_object_id, gas],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def execute_transaction(self, tx_bytes, signature_bytes, pub_key, request_type=&quot;WaitForLocalExecution&quot;):
        &quot;&quot;&quot;广播交易
        &quot;&quot;&quot;
        flag = {
            &quot;ed25519&quot;: 0x00,
            &quot;secp256k1&quot;: 0x01,
        }
        sign_b64 = base64.b64encode(signature_bytes).decode()
        serialized_sig = [flag[&quot;ed25519&quot;]] + \
                         list(base64.b64decode(sign_b64)) + \
                         list(base64.b64decode(pub_key))
        signature = base64.b64encode(bytes(serialized_sig)).decode()
        data = {&quot;method&quot;: &quot;sui_executeTransactionSerializedSig&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [tx_bytes, signature, request_type],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def transfer_object(self, from_, object_id, to, gas=1000, gas_object_id=None):
        &quot;&quot;&quot;创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        &quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_transferObject&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [from_, object_id, gas_object_id, gas, to],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers)
        return res.json()

    def move_call(self, address, package_object_id, module, function, arguments, gas_budget=10000, type_arguments=[], gas=None):
        &quot;&quot;&quot;合约交互&quot;&quot;&quot;
        data = {&quot;method&quot;: &quot;sui_moveCall&quot;,&quot;jsonrpc&quot;: &quot;2.0&quot;,&quot;params&quot;: [address, package_object_id, module, function, type_arguments, arguments, gas, gas_budget],&quot;id&quot;: str(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        return res.json()

    def sendtx(self, tx, account):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        # 1.对tx进行base64编码
        tx_b64 = base64.b64decode(tx)
        # 2. 签名 [0, 0, 0] + tx; 参考 https://github.com/MystenLabs/sui/pull/6445
        data = bytes([0, 0, 0] + list(map(int, tx_b64)))
        signature_bytes = account.sign_data(data)
        pub_key = account.get_public_key_as_b64_string()
        res = self.execute_transaction(tx, signature_bytes, pub_key)
        return res
"><code><span class="hljs-keyword">import</span> uuid
<span class="hljs-keyword">import</span> json
<span class="hljs-keyword">import</span> base64
<span class="hljs-keyword">import</span> urllib3
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> typing <span class="hljs-keyword">import</span> <span class="hljs-type">List</span>
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'accept-encoding'</span>: <span class="hljs-string">'gzip, deflate, br'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

SUI_COIN_TYPE = <span class="hljs-string">"0x2::coin::Coin&#x3C;0x2::sui::SUI>"</span>


<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, api=<span class="hljs-string">'https://fullnode.testnet.sui.io/'</span>, proxies=<span class="hljs-literal">None</span></span>):
        self.api = api
        self.proxies = proxies

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_objects</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取地址拥有的objs
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_getObjectsOwnedByAddress"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [address],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()
        
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_object</span>(<span class="hljs-params">self, obj_id</span>):
        <span class="hljs-string">"""返回指定对象的对象信息;
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_getObject"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [obj_id],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, tx</span>):
        <span class="hljs-string">"""获取交易详情
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_getTransaction"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [tx],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer_sui</span>(<span class="hljs-params">self, from_, object_id, to, amount, gas=<span class="hljs-number">1000</span>,</span>):
        <span class="hljs-string">"""创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_transferSui"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [from_, object_id, gas, to, <span class="hljs-built_in">int</span>(amount)],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">pay_sui</span>(<span class="hljs-params">self, from_, objs, to, amount, gas=<span class="hljs-number">300</span></span>):
        <span class="hljs-string">"""创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_paySui"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [from_, objs, [to], amount, gas],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">pay_all_sui</span>(<span class="hljs-params">self, from_, objs, to, gas=<span class="hljs-number">1000</span></span>):
        <span class="hljs-string">"""创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_payAllSui"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [from_, objs, to, gas],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, from_, to, amount</span>):
        objs = self.get_objects(from_)
        amount = <span class="hljs-built_in">int</span>(amount)
        sui_objs = [i[<span class="hljs-string">'objectId'</span>] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> objs[<span class="hljs-string">'result'</span>] <span class="hljs-keyword">if</span> i[<span class="hljs-string">'type'</span>] == SUI_COIN_TYPE]
        balance = <span class="hljs-number">0</span>
        pay_objs = []
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> sui_objs:
            obj = self.get_object(i)
            <span class="hljs-keyword">if</span> <span class="hljs-built_in">int</span>(obj[<span class="hljs-string">'result'</span>][<span class="hljs-string">'details'</span>][<span class="hljs-string">'data'</span>][<span class="hljs-string">'fields'</span>][<span class="hljs-string">'balance'</span>]) > amount:
                res = self.pay_sui(from_, [i], to, [amount])
                <span class="hljs-keyword">return</span> res
            balance += <span class="hljs-built_in">int</span>(obj[<span class="hljs-string">'result'</span>][<span class="hljs-string">'details'</span>][<span class="hljs-string">'data'</span>][<span class="hljs-string">'fields'</span>][<span class="hljs-string">'balance'</span>])
            pay_objs.append(i)
            <span class="hljs-keyword">if</span> balance >= amount:
                res = self.pay_sui(from_, pay_objs, to, [amount])
                <span class="hljs-keyword">return</span> res

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">merge_coin</span>(<span class="hljs-params">self, address, primary_obj_id, merge_obj_id, gas=<span class="hljs-number">1000</span>, gas_object_id=<span class="hljs-literal">None</span></span>):
        <span class="hljs-string">"""合并硬币;
        """</span>
        gas_object_id = primary_obj_id
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_mergeCoins"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [address, primary_obj_id, merge_obj_id, gas_object_id, gas],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">execute_transaction</span>(<span class="hljs-params">self, tx_bytes, signature_bytes, pub_key, request_type=<span class="hljs-string">"WaitForLocalExecution"</span></span>):
        <span class="hljs-string">"""广播交易
        """</span>
        flag = {
            <span class="hljs-string">"ed25519"</span>: <span class="hljs-number">0x00</span>,
            <span class="hljs-string">"secp256k1"</span>: <span class="hljs-number">0x01</span>,
        }
        sign_b64 = base64.b64encode(signature_bytes).decode()
        serialized_sig = [flag[<span class="hljs-string">"ed25519"</span>]] + \
                         <span class="hljs-built_in">list</span>(base64.b64decode(sign_b64)) + \
                         <span class="hljs-built_in">list</span>(base64.b64decode(pub_key))
        signature = base64.b64encode(<span class="hljs-built_in">bytes</span>(serialized_sig)).decode()
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_executeTransactionSerializedSig"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [tx_bytes, signature, request_type],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer_object</span>(<span class="hljs-params">self, from_, object_id, to, gas=<span class="hljs-number">1000</span>, gas_object_id=<span class="hljs-literal">None</span></span>):
        <span class="hljs-string">"""创建一个未签名的交易以将 SUI 硬币对象发送到 Sui 地址。 SUI 对象也用作气体对象。
        """</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_transferObject"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [from_, object_id, gas_object_id, gas, to],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">move_call</span>(<span class="hljs-params">self, address, package_object_id, module, function, arguments, gas_budget=<span class="hljs-number">10000</span>, type_arguments=[], gas=<span class="hljs-literal">None</span></span>):
        <span class="hljs-string">"""合约交互"""</span>
        data = {<span class="hljs-string">"method"</span>: <span class="hljs-string">"sui_moveCall"</span>,<span class="hljs-string">"jsonrpc"</span>: <span class="hljs-string">"2.0"</span>,<span class="hljs-string">"params"</span>: [address, package_object_id, module, function, type_arguments, arguments, gas, gas_budget],<span class="hljs-string">"id"</span>: <span class="hljs-built_in">str</span>(uuid.uuid1())}
        res = requests.post(self.api, data=json.dumps(data), headers=headers, proxies=self.proxies)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">sendtx</span>(<span class="hljs-params">self, tx, account</span>):
        <span class="hljs-string">"""广播交易"""</span>
        <span class="hljs-comment"># 1.对tx进行base64编码</span>
        tx_b64 = base64.b64decode(tx)
        <span class="hljs-comment"># 2. 签名 [0, 0, 0] + tx; 参考 https://github.com/MystenLabs/sui/pull/6445</span>
        data = <span class="hljs-built_in">bytes</span>([<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>] + <span class="hljs-built_in">list</span>(<span class="hljs-built_in">map</span>(<span class="hljs-built_in">int</span>, tx_b64)))
        signature_bytes = account.sign_data(data)
        pub_key = account.get_public_key_as_b64_string()
        res = self.execute_transaction(tx, signature_bytes, pub_key)
        <span class="hljs-keyword">return</span> res
</code></pre><p>wave3出来后，会再给大家提供个最基本的如何Mint nft的代码样例。</p><p>代码已上传：</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/sui" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/sui at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/sui&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/sui" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/sui at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/371631ce0561ea7927886542264bf1ca637beda13ade061e8990d390b505c8ec.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Aave gho稳定币项目的存款交互]]></title>
            <link>https://paragraph.com/@junjie9021-3/aave-gho</link>
            <guid>Orgi54j4wLzzUbPGCWGM</guid>
            <pubDate>Sat, 25 Feb 2023 10:34:02 GMT</pubDate>
            <description><![CDATA[aave在Goerli测试网络上推出了自家的Gho稳定币项目，支持存款，借贷，还款等交互。Aave - Open Source Liquidity ProtocolAave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.https://gho.aave.com我们用代码的方式来交互下存款，python3代码样例，可执行代码:注意: 执行前记得替换自己的私钥，默认存款0.01个""" pip3 install web3 """ import web3 import math import requests headers = { 'content-type'...]]></description>
            <content:encoded><![CDATA[<p>aave在Goerli测试网络上推出了自家的Gho稳定币项目，支持存款，借贷，还款等交互。</p><div data-type="embedly" src="https://gho.aave.com/" data="{&quot;provider_url&quot;:&quot;https://gho.aave.com&quot;,&quot;description&quot;:&quot;Aave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.&quot;,&quot;title&quot;:&quot;Aave - Open Source Liquidity Protocol&quot;,&quot;thumbnail_width&quot;:1920,&quot;url&quot;:&quot;https://gho.aave.com/&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Aave&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:1003,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1920,&quot;height&quot;:1003,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://gho.aave.com/" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Aave - Open Source Liquidity Protocol</h2><p>Aave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://gho.aave.com</span></div><img src="https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg"/></div></a></div></div><p>我们用代码的方式来交互下存款，python3代码样例，可执行代码:</p><blockquote><p>注意: 执行前记得替换自己的私钥，默认存款0.01个</p></blockquote><pre data-type="codeBlock" text="&quot;&quot;&quot;
pip3 install web3
&quot;&quot;&quot;

import web3
import math
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;accept-encoding&apos;: &apos;gzip, deflate, br&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        &quot;&quot;&quot;获取地址nonce&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxx&apos; # 这里替换成自己的私钥
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = 0.01 # 要存款的数量
    gaslimit = 299906 # gaslimit
    to = &apos;0x9c402e3b0d123323f0fced781b8184ec7e02dd31&apos; # base存款的合约地址
    method = &apos;0x474cf53d&apos; # 存款方法hash值
    amount = int(value * math.pow(10, 18)) # eth的主币精度是18位
    unit_0 = &apos;000000000000000000000000617cf26407193e32a771264fb5e9b8f09715cdfb&apos;
    addr_1 = account.address[2:].rjust(64,&apos;0&apos;) # 地址格式处理
    unit_2 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos;
    data = method + unit_0 + addr_1 + unit_2 # 拼接数据
    res = rpc.transfer(account, to=to, amount=amount, gaslimit=gaslimit, data=data) # 发送交易
    print(res)
"><code><span class="hljs-string">"""
pip3 install web3
"""</span>

<span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'accept-encoding'</span>: <span class="hljs-string">'gzip, deflate, br'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取地址nonce"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = <span class="hljs-number">0.01</span> <span class="hljs-comment"># 要存款的数量</span>
    gaslimit = <span class="hljs-number">299906</span> <span class="hljs-comment"># gaslimit</span>
    to = <span class="hljs-string">'0x9c402e3b0d123323f0fced781b8184ec7e02dd31'</span> <span class="hljs-comment"># base存款的合约地址</span>
    method = <span class="hljs-string">'0x474cf53d'</span> <span class="hljs-comment"># 存款方法hash值</span>
    amount = <span class="hljs-built_in">int</span>(value * math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>)) <span class="hljs-comment"># eth的主币精度是18位</span>
    unit_0 = <span class="hljs-string">'000000000000000000000000617cf26407193e32a771264fb5e9b8f09715cdfb'</span>
    addr_1 = account.address[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>) <span class="hljs-comment"># 地址格式处理</span>
    unit_2 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span>
    data = method + unit_0 + addr_1 + unit_2 <span class="hljs-comment"># 拼接数据</span>
    res = rpc.transfer(account, to=to, amount=amount, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>执行后打印交易hash, 去浏览器查询状态</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/">https://goerli.etherscan.io/</a></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b137b7d7fc2b7fe9bd8d568fb2f355228c3da6b38d9d815ad1fb75f52b1dee92.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>回到gho dashbord，看到我们已经地址已经有存款了</p><div data-type="embedly" src="https://gho.aave.com/" data="{&quot;provider_url&quot;:&quot;https://gho.aave.com&quot;,&quot;description&quot;:&quot;Aave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.&quot;,&quot;title&quot;:&quot;Aave - Open Source Liquidity Protocol&quot;,&quot;thumbnail_width&quot;:1920,&quot;url&quot;:&quot;https://gho.aave.com/&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Aave&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:1003,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1920,&quot;height&quot;:1003,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://gho.aave.com/" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Aave - Open Source Liquidity Protocol</h2><p>Aave is an Open Source Protocol to create Non-Custodial Liquidity Markets to earn interest on supplying and borrowing assets with a variable or stable interest rate. The protocol is designed for easy integration into your products and services.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://gho.aave.com</span></div><img src="https://storage.googleapis.com/papyrus_images/b0c74f9357f7aa6adbba5b13ad45bd27ce7be03a15888f63fea20dfd2e35da20.jpg"/></div></a></div></div><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/dfc03adfef5e1237e16224f397e705002ae69ad8c0dd1cfb855a17217de53a9e.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>代码样例已上传:</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/aave" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/aave at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/aave&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/aave" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/aave at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/b818fa38108970d13a5ca5911624c0a4b6743fb6132590934e04457a9bc2a29a.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Coinbase的L2 Base 纪念nft mint 代码示例
]]></title>
            <link>https://paragraph.com/@junjie9021-3/coinbase-l2-base-nft-mint</link>
            <guid>Z7PixgwHtt3k8JZpLkLm</guid>
            <pubDate>Sat, 25 Feb 2023 06:16:27 GMT</pubDate>
            <description><![CDATA[上篇文章写了存款的代码示例，这次来讲下如何mint主网的纪念nft: https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0 这是mint网址， mint需要花0.000777 哥ETH，大概1.28u https://zora.co/collections/0xd4307e0acd12cf46fd6cf93bc264f5d5d1598792 以下为python3代码样例:""" pip3 install web3 """ import web3 import math import requests headers = { 'content-type': 'application/json', 'accept-encoding': 'gzip, deflate, br', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/53...]]></description>
            <content:encoded><![CDATA[<p>上篇文章写了存款的代码示例，这次来讲下如何mint主网的纪念nft:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0">https://mirror.xyz/0x7b52FD04cC45B26F5bdea1CD7c8c56A00A3F859B/IeEw0Qp3MYbwFZx111fi1J25Dm8JLcm6avEHv_72R-0</a></p><p>这是mint网址， mint需要花0.000777 哥ETH，大概1.28u</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://zora.co/collections/0xd4307e0acd12cf46fd6cf93bc264f5d5d1598792">https://zora.co/collections/0xd4307e0acd12cf46fd6cf93bc264f5d5d1598792</a></p><p>以下为python3代码样例:</p><pre data-type="codeBlock" text="&quot;&quot;&quot;
pip3 install web3
&quot;&quot;&quot;
import web3
import math
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;accept-encoding&apos;: &apos;gzip, deflate, br&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        &quot;&quot;&quot;获取地址nonce&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxx&apos; # 这里替换成自己的私钥
    account = web3.Account.from_key(privkey)
    rpc = Rpc(rpc=&apos;https://rpc.ankr.com/eth&apos;, chainid=1)
    amount = 0.000777 # 要存款的数量
    gaslimit = 116900 # gaslimit
    mint_nft_token = &apos;0xd4307e0acd12cf46fd6cf93bc264f5d5d1598792&apos; # base存款的合约地址
    method = &apos;0xefef39a1&apos; # mint nft 方法hash值
    uint_1 = &apos;0000000000000000000000000000000000000000000000000000000000000001&apos;
    data = method + uint_1 # 拼接数据
    amount = hex(int(amount * math.pow(10, 18))) # 处理amount值
    res = rpc.transfer(account, to=mint_nft_token, amount=amount, gaslimit=gaslimit, data=data) # 发送交易
    print(res)
"><code><span class="hljs-string">"""
pip3 install web3
"""</span>
<span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'accept-encoding'</span>: <span class="hljs-string">'gzip, deflate, br'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取地址nonce"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    account = web3.Account.from_key(privkey)
    rpc = Rpc(rpc=<span class="hljs-string">'https://rpc.ankr.com/eth'</span>, chainid=<span class="hljs-number">1</span>)
    amount = <span class="hljs-number">0.000777</span> <span class="hljs-comment"># 要存款的数量</span>
    gaslimit = <span class="hljs-number">116900</span> <span class="hljs-comment"># gaslimit</span>
    mint_nft_token = <span class="hljs-string">'0xd4307e0acd12cf46fd6cf93bc264f5d5d1598792'</span> <span class="hljs-comment"># base存款的合约地址</span>
    method = <span class="hljs-string">'0xefef39a1'</span> <span class="hljs-comment"># mint nft 方法hash值</span>
    uint_1 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000001'</span>
    data = method + uint_1 <span class="hljs-comment"># 拼接数据</span>
    amount = <span class="hljs-built_in">hex</span>(<span class="hljs-built_in">int</span>(amount * math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>))) <span class="hljs-comment"># 处理amount值</span>
    res = rpc.transfer(account, to=mint_nft_token, amount=amount, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res)
</code></pre><p>通过交易hash在eth 浏览器查看状态</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3c9779fe6d54ec4ec2360bee7699107cf9913fd2d915e48c51da7f3d200351f6.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>现在mint nft gas费有点高，花了6u，肉疼。建议大家在低gas费时参与mint</p><p>代码样例已上传:</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/base" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/base at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/base&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/base" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/base at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/a9f8007ce73356c0ef573a6e3e6dd63d96407b32a4fde3ab7a9e82ed28204c75.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Coinbase的L2 Base 存款代码交互
]]></title>
            <link>https://paragraph.com/@junjie9021-3/coinbase-l2-base</link>
            <guid>B7twk99rEQ27RggqCcSY</guid>
            <pubDate>Sat, 25 Feb 2023 06:11:36 GMT</pubDate>
            <description><![CDATA[最近看大家在说Coinbase推出了自家L2 Base网络。Base 是一种安全、低成本、对开发人员友好的以太坊 L2，旨在将下一个十亿用户带入 web3。我们用代码的方式来交互下存款。 默认你已经具备以下知识:python3存款示例, 以下是Python3的代码示例:""" 安装依赖 pip3 install web3 """ import web3 import math import requests headers = { 'content-type': 'application/json', 'accept-encoding': 'gzip, deflate, br', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', } class Rpc: """ eth rpc方法 """ def __init__(self, rpc='https://rpc.a...]]></description>
            <content:encoded><![CDATA[<p>最近看大家在说Coinbase推出了自家L2 Base网络。Base 是一种安全、低成本、对开发人员友好的以太坊 L2，旨在将下一个十亿用户带入 web3。我们用代码的方式来交互下存款。</p><p>默认你已经具备以下知识:</p><ul><li><p>python3</p></li></ul><p>存款示例, 以下是Python3的代码示例:</p><pre data-type="codeBlock" text="&quot;&quot;&quot;
安装依赖
pip3 install web3
&quot;&quot;&quot;
import web3
import math
import requests

headers = {
    &apos;content-type&apos;: &apos;application/json&apos;,
    &apos;accept-encoding&apos;: &apos;gzip, deflate, br&apos;,
    &apos;user-agent&apos;: &apos;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36&apos;,
    }

class Rpc:
    &quot;&quot;&quot;
    eth rpc方法
    &quot;&quot;&quot;
    def __init__(self, rpc=&apos;https://rpc.ankr.com/eth_goerli&apos;, chainid=5, proxies=None, timeout=30):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    def get_transaction(self, txhash):
        &quot;&quot;&quot;获取的交易详情&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionByHash&quot;,&quot;params&quot;:[txhash],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_gas_price(self):
        &quot;&quot;&quot;获取gas&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_gasPrice&quot;,&quot;params&quot;:[],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_balance(self, address):
        &quot;&quot;&quot;获取余额&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getBalance&quot;,&quot;params&quot;:[address, &apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def get_transaction_count_by_address(self, address):
        &quot;&quot;&quot;获取地址nonce&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_getTransactionCount&quot;,&quot;params&quot;:[address,&apos;latest&apos;],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def send_raw_transaction(self, hex):
        &quot;&quot;&quot;广播交易&quot;&quot;&quot;
        data = {&quot;jsonrpc&quot;:&quot;2.0&quot;,&quot;method&quot;:&quot;eth_sendRawTransaction&quot;,&quot;params&quot;:[hex],&quot;id&quot;:1}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        return res.json()

    def transfer(self, account, to, amount, gaslimit, **kw):
        &quot;&quot;&quot;离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        &quot;&quot;&quot;
        amount = int(amount, 16) if isinstance(amount, str) else int(amount)
        gaslimit = int(gaslimit, 16) if not isinstance(gaslimit, int) else gaslimit
        gasprice = int(self.get_gas_price()[&apos;result&apos;], 16)
        nonce = int(self.get_transaction_count_by_address(account.address)[&apos;result&apos;], 16)
        tx = {&apos;from&apos;: account.address, &apos;value&apos;: amount,&apos;to&apos;: to, &apos;gas&apos;: gaslimit, &apos;gasPrice&apos;: gasprice, &apos;nonce&apos;: nonce, &apos;chainId&apos;: self.chainid}
        if kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        return self.send_raw_transaction(signed.rawTransaction.hex())
    
if __name__ == &apos;__main__&apos;:
    privkey = &apos;xxxxxxxx&apos; # 这里替换成自己的私钥
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = 0.01 # 要存款的数量
    gaslimit = 100000 # gaslimit
    base_token = &apos;0xe93c8cd0d409341205a592f8c4ac1a5fe5585cfa&apos; # base存款的合约地址
    method = &apos;0xe9e05c42&apos; # 存款方法hash值
    addr_0 = account.address[2:].rjust(64,&apos;0&apos;) # 地址格式处理
    amount = int(value * math.pow(10, 18)) # eth的主币精度是18位
    value = hex(amount) # value hex格式处理
    unit_1 = value[2:].rjust(64,&apos;0&apos;)
    unit_2 = hex(int(gaslimit))[2:].rjust(64,&apos;0&apos;)
    bool_3 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos;
    unit_4 = &apos;00000000000000000000000000000000000000000000000000000000000000a0&apos;
    unit_5 = &apos;0000000000000000000000000000000000000000000000000000000000000000&apos;
    data = method + addr_0 + unit_1 + unit_2 + bool_3 + unit_4 + unit_5 # 拼接数据
    res = rpc.transfer(account, to=base_token, amount=amount, gaslimit=gaslimit, data=data) # 发送交易
    print(res) # 打印交易hash
"><code><span class="hljs-string">"""
安装依赖
pip3 install web3
"""</span>
<span class="hljs-keyword">import</span> web3
<span class="hljs-keyword">import</span> math
<span class="hljs-keyword">import</span> requests

headers = {
    <span class="hljs-string">'content-type'</span>: <span class="hljs-string">'application/json'</span>,
    <span class="hljs-string">'accept-encoding'</span>: <span class="hljs-string">'gzip, deflate, br'</span>,
    <span class="hljs-string">'user-agent'</span>: <span class="hljs-string">'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'</span>,
    }

<span class="hljs-keyword">class</span> <span class="hljs-title class_">Rpc</span>:
    <span class="hljs-string">"""
    eth rpc方法
    """</span>
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self, rpc=<span class="hljs-string">'https://rpc.ankr.com/eth_goerli'</span>, chainid=<span class="hljs-number">5</span>, proxies=<span class="hljs-literal">None</span>, timeout=<span class="hljs-number">30</span></span>):
        self.rpc = rpc
        self.chainid = chainid
        self.proxies = proxies
        self.timeout = timeout

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction</span>(<span class="hljs-params">self, txhash</span>):
        <span class="hljs-string">"""获取的交易详情"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionByHash"</span>,<span class="hljs-string">"params"</span>:[txhash],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_gas_price</span>(<span class="hljs-params">self</span>):
        <span class="hljs-string">"""获取gas"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_gasPrice"</span>,<span class="hljs-string">"params"</span>:[],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_balance</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取余额"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getBalance"</span>,<span class="hljs-string">"params"</span>:[address, <span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">get_transaction_count_by_address</span>(<span class="hljs-params">self, address</span>):
        <span class="hljs-string">"""获取地址nonce"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_getTransactionCount"</span>,<span class="hljs-string">"params"</span>:[address,<span class="hljs-string">'latest'</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers, proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">send_raw_transaction</span>(<span class="hljs-params">self, <span class="hljs-built_in">hex</span></span>):
        <span class="hljs-string">"""广播交易"""</span>
        data = {<span class="hljs-string">"jsonrpc"</span>:<span class="hljs-string">"2.0"</span>,<span class="hljs-string">"method"</span>:<span class="hljs-string">"eth_sendRawTransaction"</span>,<span class="hljs-string">"params"</span>:[<span class="hljs-built_in">hex</span>],<span class="hljs-string">"id"</span>:<span class="hljs-number">1</span>}
        res = requests.post(self.rpc, json=data, headers=headers,  proxies=self.proxies, timeout=self.timeout)
        <span class="hljs-keyword">return</span> res.json()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">transfer</span>(<span class="hljs-params">self, account, to, amount, gaslimit, **kw</span>):
        <span class="hljs-string">"""离线交易
        account
        to: 收款地址
        gaslimit: 由当前区块的gaslimit获取
        gasprice: get_gas_price获取
        nonce: 交易总数 get_transaction_count_by_address获取
        chainId: 链id
        """</span>
        amount = <span class="hljs-built_in">int</span>(amount, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(amount, <span class="hljs-built_in">str</span>) <span class="hljs-keyword">else</span> <span class="hljs-built_in">int</span>(amount)
        gaslimit = <span class="hljs-built_in">int</span>(gaslimit, <span class="hljs-number">16</span>) <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> <span class="hljs-built_in">isinstance</span>(gaslimit, <span class="hljs-built_in">int</span>) <span class="hljs-keyword">else</span> gaslimit
        gasprice = <span class="hljs-built_in">int</span>(self.get_gas_price()[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        nonce = <span class="hljs-built_in">int</span>(self.get_transaction_count_by_address(account.address)[<span class="hljs-string">'result'</span>], <span class="hljs-number">16</span>)
        tx = {<span class="hljs-string">'from'</span>: account.address, <span class="hljs-string">'value'</span>: amount,<span class="hljs-string">'to'</span>: to, <span class="hljs-string">'gas'</span>: gaslimit, <span class="hljs-string">'gasPrice'</span>: gasprice, <span class="hljs-string">'nonce'</span>: nonce, <span class="hljs-string">'chainId'</span>: self.chainid}
        <span class="hljs-keyword">if</span> kw:
            tx.update(**kw)
        signed = account.signTransaction(tx)
        <span class="hljs-keyword">return</span> self.send_raw_transaction(signed.rawTransaction.<span class="hljs-built_in">hex</span>())
    
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
    privkey = <span class="hljs-string">'xxxxxxxx'</span> <span class="hljs-comment"># 这里替换成自己的私钥</span>
    account = web3.Account.from_key(privkey)
    rpc = Rpc()
    value = <span class="hljs-number">0.01</span> <span class="hljs-comment"># 要存款的数量</span>
    gaslimit = <span class="hljs-number">100000</span> <span class="hljs-comment"># gaslimit</span>
    base_token = <span class="hljs-string">'0xe93c8cd0d409341205a592f8c4ac1a5fe5585cfa'</span> <span class="hljs-comment"># base存款的合约地址</span>
    method = <span class="hljs-string">'0xe9e05c42'</span> <span class="hljs-comment"># 存款方法hash值</span>
    addr_0 = account.address[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>) <span class="hljs-comment"># 地址格式处理</span>
    amount = <span class="hljs-built_in">int</span>(value * math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">10</span>, <span class="hljs-number">18</span>)) <span class="hljs-comment"># eth的主币精度是18位</span>
    value = <span class="hljs-built_in">hex</span>(amount) <span class="hljs-comment"># value hex格式处理</span>
    unit_1 = value[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>)
    unit_2 = <span class="hljs-built_in">hex</span>(<span class="hljs-built_in">int</span>(gaslimit))[<span class="hljs-number">2</span>:].rjust(<span class="hljs-number">64</span>,<span class="hljs-string">'0'</span>)
    bool_3 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span>
    unit_4 = <span class="hljs-string">'00000000000000000000000000000000000000000000000000000000000000a0'</span>
    unit_5 = <span class="hljs-string">'0000000000000000000000000000000000000000000000000000000000000000'</span>
    data = method + addr_0 + unit_1 + unit_2 + bool_3 + unit_4 + unit_5 <span class="hljs-comment"># 拼接数据</span>
    res = rpc.transfer(account, to=base_token, amount=amount, gaslimit=gaslimit, data=data) <span class="hljs-comment"># 发送交易</span>
    <span class="hljs-built_in">print</span>(res) <span class="hljs-comment"># 打印交易hash</span>
</code></pre><p>通过交易hash在Goerli 浏览器查看状态，状态成功后</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://goerli.etherscan.io/">https://goerli.etherscan.io/</a></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/658ea50a5320a6c5ebbcd6398309fcdae4b100d12fda9f49c91acc434a557a53.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>再在L2 Base 浏览器查看地址余额数量，检查是否存款</p><div data-type="embedly" src="https://base-goerli.blockscout.com/" data="{&quot;provider_url&quot;:&quot;https://base-goerli.blockscout.com&quot;,&quot;description&quot;:&quot;Open-source block explorer by Blockscout. Search transactions, verify smart contracts, analyze addresses, and track network activity. Complete blockchain data and APIs for the Base Göerli (Goerli) Explorer network.&quot;,&quot;title&quot;:&quot;Base Göerli blockchain explorer - View Base Göerli stats | Blockscout&quot;,&quot;mean_alpha&quot;:63.75,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://base-goerli.blockscout.com/&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/d7cc116b0e3800b3d77dd261c558e0d8aec48f7ee9e42f7d20533ec15d93e400.png&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;Blockscout&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/d7cc116b0e3800b3d77dd261c558e0d8aec48f7ee9e42f7d20533ec15d93e400.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/d7cc116b0e3800b3d77dd261c558e0d8aec48f7ee9e42f7d20533ec15d93e400.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://base-goerli.blockscout.com/" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>Base Göerli blockchain explorer - View Base Göerli stats | Blockscout</h2><p>Open-source block explorer by Blockscout. Search transactions, verify smart contracts, analyze addresses, and track network activity. Complete blockchain data and APIs for the Base Göerli (Goerli) Explorer network.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://base-goerli.blockscout.com</span></div><img src="https://storage.googleapis.com/papyrus_images/d7cc116b0e3800b3d77dd261c558e0d8aec48f7ee9e42f7d20533ec15d93e400.png"/></div></a></div></div><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e9655d17c3ab717fc9a29c4dbf4ef5fd78eebca1193d33d927fcaa23cac9e8d6.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>代码样例已上传:</p><div data-type="embedly" src="https://github.com/junjie9021/simple-airdrop-demo/tree/main/base" data="{&quot;provider_url&quot;:&quot;https://github.com&quot;,&quot;description&quot;:&quot;Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.&quot;,&quot;title&quot;:&quot;simple-airdrop-demo/base at main · junjie9021/simple-airdrop-demo&quot;,&quot;author_name&quot;:&quot;junjie9021&quot;,&quot;thumbnail_width&quot;:1200,&quot;url&quot;:&quot;https://github.com/junjie9021/simple-airdrop-demo/tree/main/base&quot;,&quot;thumbnail_url&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;,&quot;author_url&quot;:&quot;https://github.com/junjie9021&quot;,&quot;version&quot;:&quot;1.0&quot;,&quot;provider_name&quot;:&quot;GitHub&quot;,&quot;type&quot;:&quot;link&quot;,&quot;thumbnail_height&quot;:600,&quot;image&quot;:{&quot;img&quot;:{&quot;width&quot;:1200,&quot;height&quot;:600,&quot;src&quot;:&quot;https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png&quot;}}}" format="small"><link rel="preload" as="image" href="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/><div class="react-component embed my-5" data-drag-handle="true" data-node-view-wrapper="" style="white-space:normal"><a class="link-embed-link" href="https://github.com/junjie9021/simple-airdrop-demo/tree/main/base" target="_blank" rel="noreferrer"><div class="link-embed"><div class="flex-1"><div><h2>simple-airdrop-demo/base at main · junjie9021/simple-airdrop-demo</h2><p>Contribute to junjie9021/simple-airdrop-demo development by creating an account on GitHub.</p></div><span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-link h-3 w-3 my-auto inline mr-1"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>https://github.com</span></div><img src="https://storage.googleapis.com/papyrus_images/a303994f79fc141394f6feea017019eb0e96152879642705dad0f7823815b7af.png"/></div></a></div></div>]]></content:encoded>
            <author>junjie9021-3@newsletter.paragraph.com (junjie9021)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/32d2dc5fa7c22f9c9319fbc4efe05e215e37f19d0a07d30e3835eb5380470f72.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>