-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to send bulk transactions (i.e. automatic nonce management) #335
Comments
This is something I plan to add to the cookbook, but this issue may help get you on the right track: I will likely include something similar in either ethers or in an ethers extension package, that wraps a Signer and manages the nonce as well as rebroadcasting. |
I have been trying something similar and I am getting |
This should have more to do with your backend than it does with the library. What is your Web3 setup vs. Ethers setup? In both cases are you using a Geth/Parity node? |
In both cases, it is Geth node. We have REST API client wrapped around the ethers.js. If I send 10 concurrent request calls, only one succeeds and other nine gets the replacement fee too low error. How do you suggest me to overcome this? |
In that case you will need to increment the nonce between each transaction, since each transaction when it queries the node will get the same transaction count. Your Web3 version probably used the eth_sendTransaction API call? You can do the same thing with ethers too, if you would rather the node manage your nonce, by using provider.getSigner() on the JsonRpcProvider, but then you are exposing private keys via your Geth instance. |
I will give that a try. So the difference is in eth_sendTransaction() and eth_sendRawTransaction() ?? Thanks for the quick response. |
The eth_sendTransaction (which is what The ethers_sendRawTransaction (which is what In the future, I will be adding a helper class to facilitate managing nonces, and rebroadcasting dropped transactions, since a node will only preserve a certain number of future, unconfirmed transactions for a given address... Does it make sense? The system is very eventually consistent. :) |
That's pretty clear explanation. :)
Is there any better way of doing this? |
Actually, now that I think about it, I think that I pre-populate all the values before sending them to eth_sendTransaction in JsonRpcSigner. I probably shouldn't do that, so the node can manage that. I will fix that and post a new version soon. Can you post the ABI you are using for the above example? This may help as well: https://docs.ethers.io/ethers.js/html/api-contract.html |
https://docs.ethers.io/ethers.js/html/api-contract.html#connecting-to-existing-contracts is exactly what we are doing. Will be posting the abi soon here. |
Here is the ABI : [ Please let me know if you find anything to resolve that. |
I don't see a "create" function in your ABI. In your above example did you mean |
Yeah, Sorry about that. I was not sure about the sharing the ABI and the code we had. So the code was genralised. It was |
(sorry, wrong issue) |
@ricmoo this is great, thank you. We ran into the same bulk transactions problem as we are running tests in parallel. The way we work around this issue is by wrapping an instance of Are you looking for help with this pre-population task? |
In other words, this check could probably just go away: ethers.js/src.ts/utils/transaction.ts Lines 228 to 230 in fa68385
We tried our parallel test suite after removing these lines and the nonce related errors went away. |
Oh, I’ll just remove the call to populateTransaction in JsonRpcSigner. We still need the nonce to be populated in other Signers. Sorry, I was busy today, but should be able to get it in tomorrow. :) |
@dhl Can you share the work around code that you have used if possible? |
I removed 'nonce' from the array in hexlifyTransaction function in jsonrpcprovider and It worked for me. @ricmoo May be instead of removing call to populateTransaction, removing only nonce will make sense? |
@tlxnithin I think anything not explicit should be removed, since, for example gasPrice and gasLimit may be better implemented in the eth_sendTransaction than the individual calls are using the eth_gasPrice and eth_estimateGas; for example in the upcoming wallet separation, calls to specific contracts may get different gas prices. |
This has been added in Thanks! :) |
@tlxnithin sorry mate, saw your message too late. Looks like @ricmoo just made the custom signer unnecessary. Thank you so much @ricmoo! Much obliged! |
Let me know if there are any issues, and feel free to re-open. Thanks! :) |
👍 |
Hey @tlxnithin @ricmoo How can I send a bulk of transactions without having to worry about the nonce? I havent used ether.js but web3.js has problems with it. Could you point me to a documentation or codes explaining me this as its hard to find it in internet. |
Hello,
I have a scenario where I have to send
n
transactions of my custom token ton
addresses. My plan was to create a batch transaction and send it all together. Is that even possible?I am successfully sending the token (one transaction at the time) like this
The text was updated successfully, but these errors were encountered: