Replies: 4 comments 6 replies
-
Heya! So, keep in mind that the library cannot detect That said, if you do not Part of the async operations a contract will perform is using the A call to If you are attempting to send multiple transactions without waiting for a transaction to be mined, you most certainly should use the The main reason for the Another caveat is that One more thing to keep in mind though, is that if the order of the transactions matter, you probably want to manage the transaction flow more carefully, in case transaction A fails, you may require some sort of clean-up or intervention before transaction B. Basically, stacking multiple transactions is complicated. I'm crossing my fingers we get Rich Transactions soon. :) I don't know if this really helped answer your questions directly, but hopefully it explains some of the complications. |
Beta Was this translation helpful? Give feedback.
-
@ricmoo Thanks a lot for this detailed answer. Really appreciated. Yes, Question 1: So as far as I understood, the below sets nonce on them and most definatelly, the nonces will be the same.
Which makes me believe that below will fail.
but you mention that
Which seems like that Question 2: Would your newest What do you think ? |
Beta Was this translation helpful? Give feedback.
-
Question 1 Imagine the following two cases:
The tx A will eventually request a
Now, the value of A will eventually request a But, it is important though to understand what Firstly, not all nodes will even look at the mempool (some may not even have access to one, such as light clients), so some backends will just use But even if a backend supports a mempool, imagine a system like INFURA, with 1000's of nodes across multiple data centres geographically isolated from each other. When you make a request for A, you are assigned a random node in a random data center and given the nonce X. Now you send the transaction, with nonce X to another random node in a random data center; and INFURA begins spreading this across the mempools of the 1000's of nodes. Now you request a nonce for B, which is assigned to a random node in a random data center; you might happen to hit a node that has an updated mempool and get This problem is further exacerbated by the fact that there are multiple backends (you might request Alchemy for X, send to Etherscan and ask INFURA for X+1). And each node may have its own custom rules for what it considers "likely to succeed", so the mempools can vary widely. The mempool is not a reliable source of data, and has no economic guarantees. Question 2 You would have to experiment with this. If you are thinking you could split this into two transactions A: [ X = getTransactionCount ] and B: [ sendTransaction, X+1 = getTransactionCount ], that might work but would mean you are limited to only using JSON-RPC endpoints, and still have no guarantee that the backend would always honour mempool scanning; it might work now, it might work for a bunch of requests, but there is no way to be assured it would always work on all environments. The mempool affords a lot of leeway to implementors and configuration. Recommendation In general, I would recommend handling the nonce your self (or via the NonceManager). If you have a UI, a good example to look at is the ENS manager or Uniswap interface for how to handle multiple transactions. Does that help? |
Beta Was this translation helpful? Give feedback.
-
This is hard to type, but I will try to graph it out here. Assuming: a = contract.store(1);
b = contract.store(2); We will call these requests A and B (respective to (keep in mind each request to a provider hits the network, which means that there can be an arbitrary duration for the command to execute; could be 0, or could be large, especially when the the backend is returning 429 responses, so pending operations in the event loop can literally resolve in any order after any amount of time)
// These will now pass
await a;
await b; It's hard to narrate the the ebbs and flows of the event loop, but hopefully that helps. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Richard, @ricmoo
I am having something like this:
I've not used
await
on any of them yet.Question 1: does the nonce get set on them without
await
ing ? meaning that if I doawait a && await b
now, will one of them fail because nonce was already set above on each one of them ? or does the nonce get set(getting it from getTransacionCount) when I do theawait a
?Question 2: If the answer to the above qeuestion is that nonce gets set when the
await
is used, then it means that if I callawait a && await b
together, their nonces will be the same. I guess, one way is that I don't callb
unless I waited fortx.wait()
on thea
so that it's been mined which means callingawait b
after that will get new nonce. everything correct ?Question 3: what If I still want to do
await a && await b
right away ? is theNonceManager
only solution. ?it says it's not stable and is experimental ? is it worth using it ?Beta Was this translation helpful? Give feedback.
All reactions