【问题标题】:Web3-Py : Nonce Transaction Overwriting ProblemWeb3-Py:Nonce 事务覆盖问题
【发布时间】:2021-11-29 09:59:39
【问题描述】:

你好,我正在使用 python web3 发送交易,但 nonce 是我的代码的问题

w3 = Web3(Web3.HTTPProvider("https://rpc.tomochain.com/"))
mainWallet = '0xAad6a88877E6AB7FbC33fdAce672780A85Fc88a8'
nonce = w3.eth.getTransactionCount(mainWallet)
amount_to_send = 0.01
private_key = 'xxxxxxxx'

tx = {
        'nonce': nonce,
        'to': to_address,
        'value': w3.toWei(amount_to_send, 'ether'),
        'gas': 21000,
        'gasPrice': w3.toWei('0.3', 'gwei')
    }

sign_tx = w3.eth.account.signTransaction(tx, private_key)
tran_hash = w3.eth.sendRawTransaction(sign_tx.rawTransaction)
txn = w3.toHex(tran_hash)
print(txn)

上面的代码可以很好地处理交易,但问题是当超过 1 个用户尝试撤回 nonce 问题时,假设 用户 1 请求撤回 0.001 和用户 2 请求撤回 0.002 并且他们两个同时请求然后 0.001 交易被取消,只有 0.002 通过

我该怎么做才能让他们都通过

【问题讨论】:

    标签: python blockchain ethereum web3py


    【解决方案1】:

    维护一个本地的ACID-compliant 交易并在广播之前使用随机数。 An example here.

    【讨论】:

    • 这不是很详细的兄弟
    • 我是来回答这个问题的,不是为你编写程序。编写完整的事务随机数管理系统的答案范围很广。学习并取得好成绩。
    猜你喜欢
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-22
    • 2014-06-15
    相关资源
    最近更新 更多