1

I've read many stack posts but the ones I found are either very old or do not link to updated docs where the answer can be found.

Does Ethereum have a replace by fee option similar to Bitcoin?

Canceling / overwriting a pending transaction using geth JSON RPC

How does dropping and replacing work? I'm imagining the only scenario where this plays out is when gas prices spike.

In that scenario say I have nonce 10 trx going to address A and data A. Is it possible to drop and replace with address B and data B so long as the gas price is >10% than the original nonce 10 trx?

One article states that the destination address must be the same.

Any link to docs to help understand this would be great thank you.

Nat
  • 279
  • 1
  • 8

2 Answers2

2

Looking at the go-ethereum implementation, when a transaction is being inserted into the txpool, it will first check if another transaction with equal nonce for this account exists. And if it does, it will only check that the gas price of the new one is at least priceBump higher than the old one (priceBump default value being 10%).

So it looks like you can replace a tx just by bumping the gas price up. Changing the destination address will not prevent it.

Source: https://github.com/ethereum/go-ethereum/blob/d9556533c34f9bb44b7c0212ba55a08a047babef/core/txpool/legacypool/list.go#L286-L309

jj1980
  • 151
  • 2
  • Thank you for this. Can you link to where the default priceBump is 10%? It seems in the other documentation provided there's no mention of the 10% requirement just that it be more than the previous gas price. – Nat Jul 28 '23 at 14:41
  • 1
    @Nat default priceBump value is set here: https://github.com/ethereum/go-ethereum/blob/8f2ae29b8f7743a14760e6f2b458ecddc8bb7d8f/core/txpool/legacypool/legacypool.go#L149 – jj1980 Jul 29 '23 at 00:55
1

Same nonce, higher gas fee.

It doesn't need to have the same data or address. If you want to cancel the transaction you can send yourself 0 eth (or any sum as it is coming back to you).

I know from experience though couldn't find a good written explanation. For an additional source you could look at the web3py requirements for their replace_transaction that falls back to ethSendTransaction RPC method:

If the new_transaction specifies a nonce value, it must match the pending transaction’s nonce.

If the new_transaction specifies maxFeePerGas and maxPriorityFeePerGas values, they must be greater than the pending transaction’s values for each field, respectively.

Legacy Transaction Support (Less Efficient - Not Recommended)

If the pending transaction specified a gasPrice value (legacy transaction), the gasPrice value for the new_transaction must be greater than the pending transaction’s gasPrice.

https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.replace_transaction

Will say in testing, have only needed to increase maxFeePerGas and not maxPriorityFeePerGas


Mild reinforcement of the concept:

"replacing the transaction with a slightly more lucrative one with the same nonce" https://ethereum.org/en/whitepaper/#decentralized-file-storage

Good general guide:

If the second transaction is confirmed onto the blockchain (e.g. by sending a new transaction with the same nonce and a higher gas price), the “dropped” transaction will be moved into the new transaction status category known as “Dropped & Replaced”.

https://docs.alchemy.com/docs/how-to-cancel-a-private-transaction-on-ethereum

Maka
  • 773
  • 3
  • 11
  • 1
    Thank you for this, can you confirm that the min amount to be increased is not 10%? In other words the new gas fee just needs to be higher than the last. Thank you. – Nat Jul 28 '23 at 14:42
  • You are right, it needs more than 10%. 110 gwei was "underpriced" and would not replace the 100 gwei transaction, 110.1 did. – Maka Jul 28 '23 at 16:35