A trivial doubt. #2016
-
when we call a function of the smart contract from Javascript, when is it absolutely necessary to do it like this const tx = await someContract.someFunction();
await tx.wait(1); we can use this for normal getter functions also, is there any reason to not call a function like this always? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
|
Beta Was this translation helpful? Give feedback.
-
tx.wait(1) basically means we are waiting for 1 block to be added after our transaction and code doesn't executes further until we get 1 block confirmation Code still works if you avoid tx.wait(). |
Beta Was this translation helpful? Give feedback.
tx.wait(1) basically means we are waiting for 1 block to be added after our transaction and code doesn't executes further until we get 1 block confirmation
Higher number of block confirmations finalize your transaction and you should wait for at least 6 blocks confirmations as mentioned in the course beginning so we use it to generate tx receipt (which can be useful for events emitted) after some blocks. But during testing we don't have much time to wait so we wait for 1 block.
Code still works if you avoid tx.wait().
But we should wait for some blocks to get mined