Lesson 8 : Explain this code (listenForTransactionMine). #2146
Answered
by
ameeetgaikwad
ameeetgaikwad
asked this question in
Q&A
-
What is the significance of this code, please explain in detail. function listenForTransactionMine(transactionResponse, provider) {
console.log(`Mining ${transactionResponse.hash}...`);
return new Promise((resolve, reject) => {
provider.once(transactionResponse.hash, (transactionReceipt) => {
console.log(
`Completed with ${transactionReceipt.confirmations} confirmations. `
);
resolve();
});
});
} This function is used in : async function withdraw() {
if (typeof window.ethereum !== "undefined") {
console.log("Withdrawing...");
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const contract = new ethers.Contract(contractAddress, abi, signer);
try {
const transactionResponse = await contract.withdraw();
await listenForTransactionMine(transactionResponse, provider);
console.log("Done!");
} catch (error) {
console.log(error);
}
}
} Is it same as doing this? : const transactionResponse = await contract.withdraw();
const transactionReceipt=await transactionResponse.wait(1); |
Beta Was this translation helpful? Give feedback.
Answered by
ameeetgaikwad
Aug 29, 2022
Replies: 2 comments 4 replies
-
Refer to #2140 (comment) |
Beta Was this translation helpful? Give feedback.
2 replies
-
@alymurtazamemon Help! |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ameeetgaikwad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@alymurtazamemon Help!