23

Is it possible to cancel a transaction broadcast to the blockchain?

Suppose I broadcast a transaction and want to cancel it before it has been mined. Is this possible?

This could be useful on sending an erroneous transaction containing invalid data.

  • 3
    Note that you have on average less than 30 seconds before the transaction is mined, so better catch the error pretty quick – Tjaden Hess Nov 21 '17 at 22:12
  • How could I change the nonce on new transaction ? – Anisniakan Oct 8 '18 at 5:27
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Richard Horrocks Oct 8 '18 at 9:03
  • I am quiet desperate as I made a transation from ledger live with myledger nano S, I wanted to send 4.05 ehters and then have set up 250 000 gwei, as it was asked to me, and then I saw in ledger live -9.3 ehter, fee 5.25 ether so why I AM PAYING SO MUCH FEE??? IT TOOK ABOUT 10 min for the transaction, what is possible to do, can I CANCEL THE transaction...why is ledger live not more simple to use? I feel really scammed!!! – Indiano Apr 3 at 19:38
28

It can't be canceled, but it can be "out-gassed". You can grab the nonce (can be found on the pending tx on etherscan) and send another transaction with a higher gas price with the same nonce. If you use a different nonce, then they can both be mined, but if you use the same nonce, only one can be mined. If miners see both, they should be smart enough to choose to mine the tx with the higher gas price.

  • How do you do this? could you provide code examples? – JZ. Dec 14 '17 at 7:21
  • How do you find an existing transaction and update the nonce? – JZ. Dec 14 '17 at 7:28
  • @JZ. i am going to use this guide to overwrite a pending transaction using geth downloaded from here – Kurapika May 23 '18 at 21:52
  • Okay but then how do I cancel the transaction with the lower gas price? It seems it remained stuck in the mempool. – Paul Berg Oct 25 '18 at 16:55
13

While it's not possible to explicitly cancel a transaction, you can invalidate the transaction before it's mined. The way this works is by broadcasting the same transaction using the same nonce, but with a higher gas fee. The miners are incentivized to process transactions with higer fees. If they process the newer transaction, then the old transaction becomes invalid and therefore rejected.

It's also possible to of set the gas fee too low in the original transaction and they reject the transaction after some time, but it's pretty unlikely.

Related

  • 1
    Conceptually what is the difference between cancelling and invalidating? – Sentinel Nov 21 '17 at 20:31
  • I see cancelling as an explicit request to the network to dump the transaction, and invalidating as a workaround that limitation. – Miguel Mota Nov 21 '17 at 20:51
  • Cancellation (atomicity) vs compensation (workflow). In accounting, a cancellation would be a compensation. – Sentinel Nov 21 '17 at 21:45
1

The team at Blocknative wrote an excellent post detailing Canceled Transactions that answers your question: https://blog.blocknative.com/blog/canceled-transactions

Here is what they say about Canceled TX:

What are Canceled transactions?
On Ethereum, a Cancel transaction is an attempt to overwrite a currently pending transaction with a new transaction. It's important to note that Canceled transactions are a convention and not a standard. Typically, a Cancel transaction will have:

  1. An identical nonce,
  2. From the same Wallet address,
  3. Sent to an external account (not a smart contract), with
  4. At least a 10% higher gas fee,
  5. but Zero value, and
  6. Gets signed-and-successfully-submitted before the original transaction is confirmed.

The core of the idea is that, since miners are incentivized to prioritize transactions with more gas, the cancel transaction should be confirmed before the original transaction – even though it entered the mempool later. In other words, Cancel transactions are kind of like probabilistic mulligans.

So yes, you can submit a Cancel TX to the network to try and invalidate a pending TX. But nothing is guaranteed. Once you submit a Cancel you must hope that it is mined before your original transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.