question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tx.wait() never resolves

See original GitHub issue

I’m facing a strange issue when testing with ganache and increasing my blockTime to greater than 0 to simulate network congestion and failures.

The following code works just fine (meaning it fails and returns the reason for failure) when ganache’s blockTime is 0:

try {
     let tx = await contractWithSigner.contractFunction(someData, { gasLimit: 1 });
     await tx.wait();
} catch (e) { console.log(e); }	

As soon as I increase ganache’s blockTime to any arbitrary number: ganache-cli -b 5, the same code never resolves the tx.wait() and ethers is stuck in a loop of sending out a call for transactionReceipt forever.

I can see in ganache’s output that it does indeed send out the failed transaction receipt message in the block immediately following the contract call. Is my assumption on how this should work incorrect?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:55 (16 by maintainers)

github_iconTop GitHub Comments

9reactions
Benjythebeecommented, May 11, 2021

issue still relevant

4reactions
ricmoocommented, Jul 5, 2021

Use provider.getTransactionReceipt(tx.hash); to fetch the receipt. Put the whole thing into a loop and poll for the result.

This is a scary way to do it. That should already be what the internal .wait is doing, except the .wait enforces exponential back-off and will use additional hints from the provider to optimize the network usage.

If you need an immediate solution, I would recommend using the provider.waitForTransaction(hash, confirms?, timeout?) which allows a timeout.

I’m looking into this now, and will let you know what I find shortly. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

tx.wait with Ethers.js never resolves - Stack Overflow
I'm trying to send transactions to the polygon network using ethers.js. After submitting the transaction, i await tx.wait() , but it fails to ......
Read more >
tokens - tx.wait() never resolves using ethers library
I am using ethers library in my nodejs , and trying to call a function in smartcontract which looks like: const tx =...
Read more >
迁移指南 — ethers.js 中文文档 — 深入浅出区块链
wait() returned a Promise which would resolve to the TransactionResponse once it is mined. In v4, the transaction.wait() returned a Promise which would...
Read more >
Documentation - Ethers.js
Send 1 ether to an ens name. const tx = signer. ... If the wait() method on the returned TransactionResponse is called, there...
Read more >
would transaction.wait() from ethers.js guarenteed change of ...
I have never run into an issue where the transaction succeeded without value updates. If tx.wait() fails ethers throws an error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found