Output in L-5 using metamask for deployment #4539
-
Below is the code const currentFavoriteNumber = await contract.retrieve();
console.log(`Current favNUM=${currentFavoriteNumber.toString()}`);
const transactonResponse = await contract.store("7");
//const transactonReceipt = await transactonResponse.wait(1);
const newCurrentFavoriteNumber = await contract.retrieve();
console.log(`New favNUM=${newCurrentFavoriteNumber.toString()}`);
Why is it that if we do not write the following line we get output in terminal as - const transactonReceipt = await transactonResponse.wait(1);
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
This dissent happen while using ganache |
Beta Was this translation helpful? Give feedback.
-
@Atharv-02 Write transaction takes time to update the state of the blockchain due to this we need to wait for the transaction to complete it is like the async calls in JavaScript. Without waiting for the transaction program will go further the read the blockchain state that obviously will not be updated which is why you are seeing both values same. |
Beta Was this translation helpful? Give feedback.
@Atharv-02 Write transaction takes time to update the state of the blockchain due to this we need to wait for the transaction to complete it is like the async calls in JavaScript. Without waiting for the transaction program will go further the read the blockchain state that obviously will not be updated which is why you are seeing both values same.