it("allow people to fund and withdraw", async function () {
const txResponse = await fundMe.fund({ value: sendValue });
const txReceipt = txResponse.wait(6);
const txResponse_Withdraw = await fundMe.withdraw();
const txReceipt_withdraw = txResponse_Withdraw.wait(12);
const endingBalance = await fundMe.provider.getBalance(fundMe.address);
assert.equal(endingBalance.toString(), "0");
})
The fund transaction was executed without issue and I could see the transaction detail in the Goerli testnet. But on the execution of the withdraw() transaction, it failed with the error mentioned above.
Fix that resolved the issue
I had to capture the nonce of the fund() transaction and increment it by 1 for withdraw() which resolved the issue.
Fixed code -
it("allow people to fund and withdraw", async function () {
const txResponse = await fundMe.fund({ value: sendValue });
const txReceipt = txResponse.wait(6);
const nouce = txResponse.nonce;
const txResponse_Withdraw = await fundMe.withdraw({ nonce : nouce + 1, gasLimit: 2000000});
const txReceipt_withdraw = txResponse_Withdraw.wait(12);
const endingBalance = await fundMe.provider.getBalance(fundMe.address);
assert.equal(endingBalance.toString(), "0");
})
Questions
What is nonce of a transaction? Why did I have to increment by 1 to succeed withdraw() ?
Patrick is not doing this as part of the tutorial. Is this something new added as part of new updates?
Issue Description
Below error is thrown when running staging.test
Code causing the issue
The fund transaction was executed without issue and I could see the transaction detail in the Goerli testnet. But on the execution of the withdraw() transaction, it failed with the error mentioned above.
Fix that resolved the issue
I had to capture the nonce of the fund() transaction and increment it by 1 for withdraw() which resolved the issue.
Fixed code -
Questions