简体   繁体   中英

Web3-Py : Nonce Transaction Overwriting Problem

hello I am using python web3 to send transactions but nonce is the problem my code is

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)

The Above code handle transactions well but the problem is when more than 1 user tries to withdraw nonce problem come suppose user 1 request withdraw of 0.001 & user 2 request withdraw of 0.002 and both of them request at the same time then the 0.001 transactions got canceled and only 0.002 passed

What can I do so the both of them pass

Maintain a local ACID-compliant of transactions and used nonces before broadcasting them out. An example here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM