I use web3 and provider mainnet. I do 2 transactions by contract. first is approve method and another transaction is multitransfer. I store second signature in database. if first transaction is success I send second transaction/. second transaction almost always error nonce too low`. how i can solve this problem
How do I customize the nonce when sending a transaction? Click the 'Custom nonce' field to enter the number you need, and, when you're ready to submit the transaction, 'Confirm'. Press 'Save' to confirm your choice.
A Nonce of "0" means that it is the first transaction executed from a particular wallet. The Nonce value is incremented in the order of "1" in each sequential transaction.
A nonce is the number of the transaction of the sender's address. Every transaction from an address is numbered sequentially, beginning with 0 for the first transaction. For example, if the nonce of a transaction is 10, it is the 11th outgoing transaction sent from the sender's address.
For proper nonce management you have 2 options :
Request the nr of transactions confirmed for your address with web3.eth.getTransactionCount(ethAddress), increment, send and wait for receipt before processing the next one. This is very slow if you need to have high-throughput and you are relying on a specific node to be available and to be synced.
You maintain your own local counter persisted at the level of the database. Use the DB's access locks to handle possible concurrent requests and return correct values every time. You do not want to keep this counters in memory as they will be lost if your application crashes or restarts. This is very efficient as you do not need the node and you can send as many transactions as you can dish out. If something goes wrong... (nonce too low) reset to the value of web3.eth.getTransactionCount(ethAddress).
Important Note: You might wonder why not to use web3.eth.getTransactionCount(ethAddress, 'pending'). This is because the 'pending' option makes the call unreliable as its hard for the nodes to have an accurate number of transaction in the queue & the memory pool.
For a better understanding how the nodes look at your message's nonce. Check this answer here : https://ethereum.stackexchange.com/questions/2808/what-happens-when-a-transaction-nonce-is-too-high/2809#2809
And this one too : Send Raw Transaction Ethereum infura nodejs npm
There may be two issues(solutions) here from my understanding; 1) You may have to manually increment nonce for the gas estimation of the multitransfer operations. 2) Some server are pretty slow these days, so either you fetch transactionReceipt(poll) of first transaction before doing the second to be sure that it has been mined. This way you would likely have the right nonce for second transaction. However, if you are lazy to do this, just are reasonable delay between the two transactions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With