I have a dapp that, as part of one logical user operation, must issue an approve() call on a token contract followed by a call to another contract that will use the funds. Since these each require user-authorization I have to issue them at about the same time. Some options that I can see include:
- Submitting both sequentially but as fast as possible (the nonce will keep them ordered).
- Chaining (waiting) on the approve tx until I get its transaction hash and then submitting the transfer tx.
- Chaining as in #2 but introducing a short artificial delay between submissions.
- Using the batch API?
I am currently doing #2 (chaining). The effect that I see is that normally the user gets two popups to confirm and it is fine. (I have seen Metamask combine them into one dialog sometimes but I don’t know what triggered this - timing related?). The problem is that occasionally this just seems to fail and one of the transactions is never presented to the user. I’ve had reports of this happening on multiple platforms and in multiple wallets.
Is this what #4 (the batch API) is for? I did some experiments with it but it appeared to me that no one was using this API and it was a bit dated. I was concerned about how well supported it was in various wallets and I wasn’t sure it actually helped the issue.
EDIT: Another issue that may rule out the batch API is that it does not appear to provide a way to get the transaction hashes for the submitted transactions, making it impossible to monitor them properly.
Thanks!