You can set nonce in MetaMask but it is hidden by default. You may want to set your nonce because the gas prices are high and you want to unstuck your transaction. By setting your own nonce, you can try to override a pending transaction. You may not be able to do this via the MetaMask UI – for example if you imported your Ethereum wallet.
This is especially useful if you have a stuck transaction on MetaMask due to low gas and want to try to cancel it.
Update: If you are having trouble with gas prices, make sure to use GasNow or ETHGasStation for the latest gas prices instead of relying on the MetaMask default gas prediction. If you are trading, look for best execution on 1inch instead of going directly to sites like Uniswap, Sushiswap, Balancer etc. since 1inch can aggregate across all of them and give you best execution and better pricing.
Before we begin, note that you need to double-check the nonce that you’re setting. If you set the nonce too low or too high, the transaction won’t get confirmed. This is definitely for advanced users of MetaMask and Ethereum, so do this with care. Read more about nonce on Stack Overflow. The information below assumes you know about nonce on Ethereum.
Now that you’re ready, let’s get down to setting your own nonce in your MetaMask
Step-1: Go to your account on the top right corner of your MetaMask extension and click on Settings.
Step-2: Under Settings, click on Advanced Settings. Then find the setting that says: “Customize transaction nonce” Turn this on to change the nonce (transaction number) on confirmation screens. This is an advanced feature, use cautiously. Toggle this to “ON” state.
Step-3: Now you can create a transaction as you normally would (e.g. if you want to send a 0 ETH transaction to yourself) and you’ll see a new field appear called “Set Custom Nonce“. This will show up in the confirmation screen when you try to send the transaction out.
Here, we have manually set the custom nonce to 10000. Make sure you double check the nonce value!
When you hit confirm, MetaMask will broadcast your transaction with the custom nonce that you chose above.
How to Cancel a MetaMask Transaction?
Now that you know how to set a custom nonce in MetaMask, it is time to learn how to cancel a transaction in MetaMask. Why would you need to cancel a transaction? Mostly because gas prices can fluctuate a lot on Ethereum.
Let’s say you create an expensive transaction, like creating a new Balancer pool or a Tornado Cash withdrawal. These can be > 1MM gas operations, which at current ETH prices and gas prices can be up to $500 or more. If you create these transactions at a lower gas price, you can hope they eventually get confirmed but that is not a guarantee. After a while, you may simply wish to cancel the transaction.
MetaMask provides a native way to cancel the transaction when you click into your most recent pending transaction. However, this is far from ideal. The reason is that MetaMask does not let you customize the gas price to set on the cancelation. See the experience below – they decide the gas price, set at 10% higher than whatever you set the gas for the original transaction, not based on the most recent gas price of the network.
Instead, they default it to 10% more than the previous one. This can cause a lot of headache where you can continue trying to speed up the transaction by flooding the network with increasing gas costs. Not ideal.
Instead, a better method is to follow this guide:
Step-1: Enable custom nonce on MetaMask as described above.
Step-2: Find out the nonce of the transaction you wish to cancel (e.g. via Etherscan)
Step-3: Create a new transaction sending 0 ETH from your address to your address. Make sure this is the same address as the one you are trying to cancel the transaction from. This will be the cheapest way, since an ETH send is 21,000 gas, the lowest amount.
Step-5: Check etherscan to make sure the new transaction is confirmed before the old one that you are trying to cancel. The old one will be shown as ‘Dropped and Replaced’ on Etherscan. This means the old transaction is canceled.
What to do if a transaction is stuck (e.g. on Matic or BSC) on MetaMask and you can’t speed it up?
This issue happens sometimes especially on non-Ethereum services. Now that MetaMask has become the entry point for many other blockchains, this issue has been popping up more and more.
The underlying reason for this is that sometimes the nodes will drop a transaction completely due to the volume. Now you are stuck – the network thinks you are at nonce “n” whereas MetaMask thinks you are at nonce “n+1”. This means if you broadcast another transaction, then the network will reject it (or keep it in a cache) since the nonce is out of sync. The network is expecting “n” nonce but your MetaMask sends “n+1” nonce.
To solve this problem, you can follow one of two approaches:
Method-1: Set the nonce manually as described above to a value that is 1 more than the previously confirmed transaction. You may need to look at a block explorer to find out the right nonce. Then, send yourself a 0-value transaction with this nonce.
Method-2: Go to Settings > Advanced > Reset Account. This will clear your local data and history so make sure you are ok with this. Once you confirm, your nonce will be reset as well, along with the pending transactions that would previously have shown up in your account.