Putting your Foot on the Gas: How-To Cancel/Replace ETH Transactions

Putting your Foot on the Gas: How-To Cancel/Replace ETH Transactions

By Mynima | Hobbyist Mining | 20 Sep 2020


Introduction

I hope everyone that was due their UNI token airdrop has successfully claimed it. While claiming my airdrop and sending to Binance (for a little trading) I ran into a few issues that I thought would be good to share with folks. If you've ever had a transaction sit on pending for a long time and worried about what you can do to speed it up or cancel then this one is for you. Bear in mind the following information does not come with any sort of guarantee.

Normally the transactions are processed so fast that you're not going to get a chance to change your mind, however, on the odd occasion when you're sat on pending you have an opportunity to do just that. One word of caution, it is highly likely that you're going to end up spending more gas than you initial anticipated so make sure you are aware of this before you start. If you don't have the ETH balance to cover the gas then you're just out of luck (at least until you top up your address).

 


Pending Transactions (one at a time)

The traditional process flow, albeit simplified, for performing transaction on the blockchain is something a bit like this:

flow  

In this process we submit transaction with a given gas price we're willing to pay for the transaction to be processed. The miners will pick up these transactions giving preferential treatment to those that pay higher gas, after all it is more profitable for them this way. Right now we're in the middle of an arms race with the network being pushed to its limits. This means that as more an more transactions occur the prices of gas are creeping up as folks who can afford it jump to the front of the queue.

block

Just the other day I submitted a transaction and put in somewhere around 300 Gwei which (at the time) the ETH gas station suggested was <5min. Then the price seemed to spike and, would you know it, an hour went by and my transaction was sitting there. All the while folks were coming along and throwing out 450+ gas prices and having their transactions validated and added to the blockchain. My initial thought was "okay, so I wait. I've got other stuff to do in the meantime" then when I hit the 2-3 hour mark I started to think perhaps there is something I can do. This is where I went back to MetaMask (where I executed the transaction) and first tried the "Speed up" option, then the "Cancel" option, then the "Speed up Cancellation". Then came back to it later and got a transaction failed message, not ideal but happens. So I submit my transaction again, doing due diligence I went to etherscan.io and I see a message like this (below) on my transaction (note this is not my transaction, just picked this out of the current pending transactions):

another

So this looks weird right? But if we click on "Txn Hash#" we would be taken to the transaction (which is still pending) that was submitted prior to this. Of course if there were multiple you'd just be taken to the one before, which then looks similar this and then the one before that and so on. So how does the blockchain know which one to do first and therefore why is this at the back of the queue?

The answer to this is the "Nonce", which is effectively a sequential number that your wallet gives each transaction you submit. Normally you submit a transaction and it steps forward one, the transaction confirms and you're all good. But when your transactions get stuck and not mined (validated), you effectively end up with a pile-up. All you are doing, when submitting subsequent transactions is adding them to the queue, which is stuck behind that one pending transaction that has failed in the first place.....this is an absolute pain in the neck. To use the car analogy a little more, your engine begun to stall and what we need to do is give it a little more gas to get a going again.

 


First Things First (MetaMask)

Before going into any slightly more elaborate steps of cancelling or replacing the transaction manually, if you performed your transaction via MetaMask and it is still visible as pending in your transaction history, you can use the built in "Speed up" or "Cancel" functionality.

meta_replace

Here you have the option to spend some gas to either cancel the transaction outright or perhaps speed up the transaction by increasing the gas fee. In reality what we're doing with both of these options is actually the same as the manual process and that is we're trying to perform a switcheroo on that first pending transaction and get the miners to finally incorporate the transaction into a block.

The one downside with this approach is that we have less flexibility of modifying the details of the transaction (i.e. the amount/address) and also if the transaction doesn't appear in your MetaMask with these options (as was the case for me) you're stuck wondering what you can do. This is where we move on the options below.

 


Cancelling or Replace a Transaction

So, as I alluded to earlier, the key to replacing or cancelling any pending transaction lies with the Nonce. The relative order with which we submit a transaction. We also know that miners will give preferential treatment to high gas fees (as they would earn more) and there in is the combination. What we need to do is two things:

  • Create another transaction with the same Nonce as the first (i.e. making it the same relative order in the queue)
  • Up the gas fee incentive to mine that transaction first (thereby meaning the other is disregarded)

 

Getting the right information:
  • Head over to Etherscan.io to locate your pending transaction
  • Once on the transaction we need a few bits of information (click on the small blue down arrow to see all the info):
    • 1) The address to which we're sending the transaction
    • 2) The Gas Price we attempted to pay to submit the transaction
    • 3) The Nonce value of the transaction

transaction 

 

Making the switch:
  • With the relevant information to hand we now need to head to our wallet:
  • We can then enter the relevant information (example below is with MyCrypto):
    • 1) Enter the destination address - This is where we make the decision of changing the from replace to cancel. If replacing we want the original destination address, otherwise if we want to cancel it we just put our own address
    • 2) Add the transaction amount - Similar to the previous step, to replace we can put the same amount, or even modify the amount, to cancel we just want to put 0 as we don't really want to move any funds
    • 3) Modify the Gas price - Now this is where it can get expensive. The best option is to go to https://ethgasstation.info/ and to put in the fastest current price (provided this is more than your original transaction). Otherwise, adjust as you see fit but make sure that you put in a gas price greater than your original price, we're trying to make the transaction more likely to get picked up first.
    • 4) Finally, we can add the Nonce value making sure it matches that of the pending transaction we're trying to replace/cancel.

replace 

All being well (and after re-checking) you can click send transaction and you're away.

 

MetaMask Tip: if you want to be able to do this all through MetaMask you can just need to go to Settings>Advanced and make sure the following options are switched on:

  • Advanced gas controls
  • Customize transaction nonce

metamask

 


Final Thoughts

As I said in the introduction there is no guarantee with this process. If you catch it at the wrong time and put in a higher gas price only for all the prices to have spiked, and you to be left waiting again, you may well need to go through the process again. My one bit of advice (this is coming from someone who has made this mistake a lot of times), don't cheap out on gas just to save a buck or two. If transaction prices are high ask your self a question:

Do I need to make this transaction now? Can it wait?

By far the safest option is to wait til you're on more stable ground with the price of gas. If you cannot wait then ask yourself:

Will the additional couple of bucks to set the transaction to the 'Fast' option break the bank?

If you absolutely must make a transaction because it is a time sensitive trade then don't get caught waiting on pending for hours. I've played with the gas prices a few times when making trades and rarely has it been a good idea to try and shave off a little extra by limiting the transaction. Remember you're setting a limit to the fees you'll pay not a minimum, it could well be that not all the gas is used up in which case you only pay what was used.

Finally, double, triple and quadruple check your amounts, gas prices and most importantly addresses. There have been a lot of war stories lately of people sending funds to random addresses by mistake. Scammers want your funds so do not, under any circumstance blindly send funds to an address, you'll only regret it later.

 

Hope you all enjoyed the guide and find it useful, stay safe out there, good luck y'all! 

 


If you liked this and want to read more check out my back catalogue here:
https://mynima.github.io/



References:
https://support.mycrypto.com/how-to/sending/checking-or-replacing-a-transaction-after-it-has-been-sent
https://kb.myetherwallet.com/en/transactions/checking-or-replacing-a-tx-after-sending/ 
https://guides.curve.fi/how-to-drop-and-replace-a-stuck-transaction/


Mynima
Mynima

Hobby miner and Crypto interested programmer. https://mynima.github.io/


Hobbyist Mining
Hobbyist Mining

Tips and how-to guides from one beginner to another.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.