DEV Community

foxgem
foxgem

Posted on • Edited on

1

Troubleshooting: replacement fee too low

Symptom

Calling a contract method returns the following error message:

Error: replacement fee too low (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"jsonrpc\":\"2.0\",\"id\":109,\"error\":{\"code\":-32000,\"message\":\"replacement transaction underpriced\"}}","error":{"code":-32000},"requestBody":"{\"method\":\"eth_sendRawTransaction\",\"params\":[\"... \"],\"id\":109,\"jsonrpc\":\"2.0\"}", "requestMethod": "POST", "url":"..."} , method="sendTransaction", transaction="..." , code=REPLACEMENT_UNDERPRICED, version=providers/5.5.2)
    at Logger.makeError (... /node_modules/@ethersproject/logger/lib/index.js:199:1)
    at Logger.throwError (... /node_modules/@ethersproject/logger/lib/index.js:208:1)
    at checkError (... /node_modules/@ethersproject/providers/lib/json-rpc-provider.js:111:1)
    at InfuraProvider.<anonymous> (... ) /node_modules/@ethersproject/providers/lib/json-rpc-provider.js:659:1)
    at step (... /node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:1)
    at Object.throw (... /node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:1)
    at rejected (... ) /node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:1)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Enter fullscreen mode Exit fullscreen mode

Cause

This error message has included a clear reason already: replacement fee too low. But, what does it mean? To a new comer of Ethereum, it is confusing.

In short, it implies you are sending two txes with the same nonce but the gas prices in these two txes are almost the same. At least, there are no big difference between two.

There are two possible reasons for this:

  • The same account are submitting two txes within a short period of time, which results in the same nonce being used for these two txes. Of course, the gas prices in these two won't be changed too much.
  • The price was set incorrectly when a tx was being cancelled or accelerated.

You can find more details in this ethers github issue.

Solution

One simple solution is to slow down the speed of sending tx and submit a tx after the previous tx is confirmed.

const tx = await contract.writeMethod(...) ;
await tx.wait();
Enter fullscreen mode Exit fullscreen mode

Another is to set a reasonable gas price when you plan to cancel or speed up a tx.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more