【发布时间】: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