Sending transactions with automatic nonce increments #1522
Replies: 6 comments 1 reply
-
Batching is not supposed in the ethers current set of Providers, but I am working on a JsonRpcProvider which will implicitly batch. Keep in mind the nonce has nothing to do with Providers in ethers, as Providers and Signers are completely separate ideas. If you want the nonce incremented, consider using the NonceManager, which is a sub-class of Signer, which wraps another Signer and managers the nonce for you. Does that help? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply on this one. Making multiple successive transactions just doesn't seem to work well. It is fine to increase the nonce on each transaction, but if one fails or the nonce otherwise gets skewed, bad things ensue. Seems a contract wallet may be the way to go. Not sure how the large services batch their transactions or serialize them, but it seems a pain. |
Beta Was this translation helpful? Give feedback.
-
A contract wallet will end up having the same issue from the EOA used to drive it. The NonceManager is fairly simple right now, but in the future will support rebroadcast, which is the problem you are experiencing. The transaction pool (by default) will only handle a handful of pending transactions for a given account. If you overrun that it will start dropping the later ones, and you will need to rebroadcast the transactions for the current nonce and beyond. Most services that require sending large numbers of transactions, would have this sort of rebroadcast service. Or run their own node; I believe if you use a private key controlled by a node, it will handle this for you. How many transactions are you trying to broadcast at once? |
Beta Was this translation helpful? Give feedback.
-
I am writing a service that has unknown transactions, which is why batching would be great. |
Beta Was this translation helpful? Give feedback.
-
You can do it with NonceManager unconfirmed. The only issue I've seen lately is in some errors if the provider replies with insufficient funds, the nonce still gets incremented and future transactions won't get mined unless you send a transaction using the nonce from the failed transaction. |
Beta Was this translation helpful? Give feedback.
-
That is an example of why the NonceManager needs to be more complex with callbacks, because neither situation makes sense to default on; sometimes a failed transactions should be retried, and sometimes a failed transaction is safe to ignore. That functionality will not be added to NonceManager anytime soon though; for complex features like that you will need write some additional logic yourself. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I believe I have asked about batching transactions before, and seem to recall that ethers does...not(?) support batching???
In looping through the getLogs array, would it be best to batch the transactions and send them in one go, or increment the nonce and create n transactions? It seems as thought the nonce doesn't increase until a transaction is mined, and rather than waiting for each transaction to confirm, before sending the next, incrementing the nonce and sending multiple transactions seems to be the way to go, but that isn't working out so well.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions