DEV Community

foxgem
foxgem

Posted on • Updated on

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.

Top comments (0)