[Ethereum] Send transaction with same nonce as another transaction but lower gas price

nonceraw-transactionweb3js

I want to send a transaction using web3, and I want this transaction to have the same nonce as other transactions – so far so good. The issue comes when I set a lower gasPrice than the other transactions. When I do this, I get an error:

Replacement transaction underpriced

I am aware that the transaction is underpriced compared to the existing ones, but still I want it to issue the transaction instead of throwing an error and messing up the whole program.

Is there a way to circumvent this? Should I use any other API for this purpose? or am I doomed to always be the highest bidder?

Thanks

Best Answer

It doesn't make any sense to send the same transaction with lower gasPrice: If both transactions are in mempool, the miners pick the transaction with the higher gasPrice (your first transaction), so there's no need to add the second one.

If, for whatever reasons, you really want to have the same transaction with lower gasPrice, you could do the following:

  • cancel the pending transaction - this costs gas, because it actually sends a 0 ETH transaction to itself, with a higher gasPrice than the original tx
  • re-submit the original tx (with its nonce increased ), with a lower gasPrice

I can't imagine any scenario where this would be of any help, but it's definitely possible.