Web3-Py: Nonce事务覆盖问题



你好,我使用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个用户试图立即撤回问题来假设用户1请求提取0.001 &用户2请求提取0.002,他们同时请求,然后0.001事务被取消,只有0.002通过

我怎么做才能让它们都传递

在广播事务和使用的随机数之前,维护符合本地acid的事务和随机数。这里有一个例子。

最新更新