NonceManager increments nonce even if transaction fails
See original GitHub issueI understand this isn’t trivial to fix fully, but if a transaction fails to send (e.g. with insufficient balance), the nonce is wrong afterwards and every future transaction also fails.
I think these easy cases should be fixable by just doing
try {
const tx = await this.nonceManager.sendTransaction({
to: i.address,
value: parseEther(i.amount),
});
} catch (e) {
console.error("could not send tx", "nonce=", e?.transaction?.nonce);
this.nonceManager._deltaCount--;
}
except inside the sendTransaction function
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Does nonce increase when the transaction fail?
There is no hard requirement that it increments every time although wallets tend to do that in the background. Given that transactions must...
Read more >Managing nonces - Nethereum Documentation
Each node will process transactions from a specific account in a strict order according to the value of its nonce, hence the nonce...
Read more >ethers-io/Lobby - Gitter
The nonce manager will fetch the latest from the backend, and then increment ... don't even know if they support a paid level...
Read more >Sending Web3 Transactions In Node.js — Nonce Hell.
It starts at zero for your first transaction and increments by one (+1) for subsequent transactions. This allows each transaction from an address...
Read more >Experimental - ethers
The NonceManager is designed to manage the nonce for a Signer, automatically increasing it as it sends transactions. Currently the NonceManager does not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@phiresky yes, this nonce(which is not even nonce but really serial counter) thing is really bad. Imagine in real life you run a business and issued 10 checks to your suppliers and if the first one is not cashed, the other 9 can’t either. You would be out of business in no time.
We have to re-design our application to use multiple ‘agent’ wallet and put our serialization logic(if needed) in the contract logic itself. Though most of the time, there doesn’t need to have serialization. Say a typical ERC20(like the above situation), it would go through so long the balance is enough, regardless when the transaction is picked up(gas price can be different).
We have done some extensive work on this and I can tell you that what we have settled on is:
Now we do work on consortium chains, so we do not often have issues with nodes accepting TX and then halfway through losing one in the middle of a run.