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.

Differing `wait` and `waitForTransaction` behaviors

See original GitHub issue

This is a bit of an interesting one!

We have a TransactionResponse that we register a wait() callback on a la:

const response = await signer.sendTransaction(...);
response.wait(r => console.log(r)).catch(e => console.log(e))

The response.hash is also passed to a helper that calls provider.waitForTransaction.

The transaction in question (0xd63407185e358f82bb87ec31e91e841fc2d34e8d23c36e7b44ca03573997a7b3 on xdai) hard-errored in wait(), but hung in waitForTransaction. Is there a better way to get the same behavior in both callbacks?

Here are some logs that may be useful for you from the instance:

  • Repl check of transaction
> const eth = require("ethers");

> const p = new eth.providers.JsonRpcProvider("https://rpc.xdaichain.com/");

> p.getTransaction("0xd63407185e358f82bb87ec31e91e841fc2d34e8d23c36e7b44ca03573997a7b3").then(r => console.log(r)).catch(e => console.log("error", e))
> null

> p.getTransactionReceipt("0xd63407185e358f82bb87ec31e91e841fc2d34e8d23c36e7b44ca03573997a7b3").then(r => console.log(r)).catch(e => console.log("error", e))
> null
  • Error from wait callback:
{
   "time":1617720629536,
   "method":"sendTxAndParseResponse",
   "error":{
      "message":"processing response error (body=\"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"error\\\":{\\\"code\\\":-32000,\\\"message\\\":\\\"Block information is incomplete while ancient block sync is still in progress, before it's finished we can't determine the existence of requested item.\\\"},\\\"id\\\":4691}\\n\", error={\"code\":-32000}, requestBody=\"{\\\"method\\\":\\\"eth_getTransactionReceipt\\\",\\\"params\\\":[\\\"0xd63407185e358f82bb87ec31e91e841fc2d34e8d23c36e7b44ca03573997a7b3\\\"],\\\"id\\\":4691,\\\"jsonrpc\\\":\\\"2.0\\\"}\", requestMethod=\"POST\", url=\"https://rpc.xdaichain.com/\", code=SERVER_ERROR, version=web/5.1.0)",
      "type":"Error",
      "context":{
         
      },
      "stack":"Error: processing response error (body=\"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"error\\\":{\\\"code\\\":-32000,\\\"message\\\":\\\"Block information is incomplete while ancient block sync is still in progress, before it's finished we can't determine the existence of requested item.\\\"},\\\"id\\\":4691}\\n\", error={\"code\":-32000}, requestBody=\"{\\\"method\\\":\\\"eth_getTransactionReceipt\\\",\\\"params\\\":[\\\"0xd63407185e358f82bb87ec31e91e841fc2d34e8d23c36e7b44ca03573997a7b3\\\"],\\\"id\\\":4691,\\\"jsonrpc\\\":\\\"2.0\\\"}\", requestMethod=\"POST\", url=\"https://rpc.xdaichain.com/\", code=SERVER_ERROR, version=web/5.1.0)\n    at Logger.makeError (webpack:////app/node_modules/@ethersproject/logger/lib/index.js?:180:21)\n    at Logger.throwError (webpack:////app/node_modules/@ethersproject/logger/lib/index.js?:189:20)\n    at eval (webpack:////app/node_modules/@ethersproject/web/lib/index.js?:266:32)\n    at step (webpack:////app/node_modules/@ethersproject/web/lib/index.js?:33:23)\n    at Object.eval [as next] (webpack:////app/node_modules/@ethersproject/web/lib/index.js?:14:53)\n    at fulfilled (webpack:////app/node_modules/@ethersproject/web/lib/index.js?:5:58)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:93:5)"
   },
   "msg":"Transaction reverted"
}```

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
zemsecommented, Apr 7, 2021

There is a difference in provider.waitForTransaction and tx.wait() that:

  • waitForTransaction will resolve once transaction is mined even if the actual transaction was success or reverted.
  • tx.wait will be pending until transaction is mined (using waitForTransaction under the hood) and will resolve or reject based on tx was success or reverted.
1reaction
zemsecommented, May 21, 2021

the account that I was doing the transaction on had no currency, so it couldn’t pay the gas fees.

Hey, what backend were you using? Because this could be a bug in that code base, I think the node should give a JSON RPC ERROR when someone is submitting such a tx (unless there is a pending tx in mempool that is funding this account).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Ethers.js
Ethers' various Classes and Functions are available to import manually ... the transaction has been mined, consider the waitForTransaction method below.
Read more >
Bountysource
Differing `wait` and `waitForTransaction` behaviors.
Read more >
MySQL 5.6 Reference Manual :: 14.7.1 InnoDB Locking
A transaction waits until the conflicting existing lock is released. If a lock request conflicts with an existing lock and cannot be granted...
Read more >
AlchemyWeb3.js Quickstart - Alchemy Docs
This behavior can be configured by passing the following options when creating ... The minimum time waited between consecutive retries, in milliseconds.
Read more >
Postgres wait for transaction to finish - database - Stack Overflow
... as the transaction cannot be serialized - then it will fail. That's how it works by design. And, no, you cannot change...
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