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.

WaitForTransaction() incorrectly times out (the transaction was immediately mined)

See original GitHub issue

Describe the bug A transaction was submitted and quickly mined on the network; however, waitForTransaction did not return and in fact ended up failing as if the transaction was not mined/confirmed.

Here is the place where waitForTransaction is used in our application: https://github.com/graphprotocol/indexer/blob/552061320c50635094af3b1fdc12d2d981a0e6a1/packages/indexer-agent/src/network.ts#L182-L185

Environment:

  • The issue was noticed on a Node application running on a GCloud cluster VM (Ubuntu) talking to an Alchemy API Rinkeby endpoint.
  • Ethers v5.1.0
  • Using a StaticJsonRpcProvider

Search Terms waitForTransaction(), transaction incorrectly timed out

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ricmoocommented, Apr 21, 2021

I’ve been trying to reproduce this but cannot.

Do you possibly have a long running CPU intensive test that does not yield to the event loop? Are you using your own API key?

Can you try out this script, and see if you see the same problem? I’m wondering if it is a link/firewall issue:

const { ethers } = require("ethers");

let lastNow = null;
function getTime() {
    const now = (new Date()).getTime();
    if (lastNow == null) { lastNow = now; }
    const result = parseInt(String(now - lastNow)) / 1000;
    lastNow = now;
    return result;
}

(async function() {
  const provider = new ethers.providers.AlchemyProvider("ropsten");

  while (1) {
    // reset the timer
    getTime();

    // Get the current block
    const blockNumber = await provider.getBlockNumber();
    console.log(`Block Number (${ getTime() }):`, blockNumber);

    // Get a transaction to test
    const txs = (await provider.getBlockWithTransactions(blockNumber)).transactions;
    if (txs.length === 0) { continue; }
    const tx = txs[0];
    console.log(`Transaction (${ getTime() }):`, tx.hash);

    //console.log(`Receipt before wait (${ getTime() }):`, await provider.getTransactionReceipt(tx.hash));

    // Wait for the receipt
    try {
        const receipt = await provider.waitForTransaction(tx.hash, 3, 0);
        console.log(`Receipt after wait (${ getTime() }):`, receipt.confirmations);
    } catch (error) {
        console.log(`Receipt after wait error (${ getTime() }):`, error);
    }

    console.log("=========================");
  }
})();

Also, it shouldn’t matter, but can you also remove your node_modules/, package-lock.json (and yarn lock file if you use yarn) and do a new npm install to get the latest versions?

I’ve also tried setting the number of confirmations to a very large number and the timeout to smaller values, and the timeout seems to be honoured.

If you can tweak this script to reproduce the problem too, that might help me figure out the issue.

Thanks! 😃

0reactions
ricmoocommented, Apr 12, 2022

@peterbraden What do you mean? It registers a callback using .on, so it will be called on every block after the transaction is mined. It is not using .once.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WaitForTransaction() incorrectly times out (the transaction was ...
Describe the bug. A transaction was submitted and quickly mined on the network; however, waitForTransaction did not return and in fact ended up ......
Read more >
ERC20 transaction not throwing error but balance is not ...
provider.waitForTransaction(tx.hash,3) . The third argument is milliseconds for timeout error. If you pass 0, it will immediately trigger error.
Read more >
tx.wait with Ethers.js never resolves - Stack Overflow
waitForTransaction (hash,confirmations,timeout). You can do something like this: const ethers = require("ethers"); const provider = ...
Read more >
Documentation - Ethers.js
To stall until the transaction has been mined, consider the waitForTransaction method below. await provider.getTransactionReceipt(" ...
Read more >
web3.eth — web3.js 1.0.0 documentation - Read the Docs
Incorrect checksum addresses will throw an error when passed into functions. ... transactionBlockTimeout; > 50 // set the transaction block timeout web3.eth ...
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