Web3-Py:Nonce 事务覆盖问题

Web3-Py : Nonce Transaction Overwriting Problem

你好,我正在使用 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 笔交易通过

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

维护本地 ACID-compliant of transactions and used nonces before broadcasting them out. An example here