How to Set Nonce in Metamask

By btcgeek | DeepResearch | 22 Apr 2021


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.

Note: If you are having trouble with gas prices, make sure to use GasNow and not ETHGasStation for the latest gas prices.

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.

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.

MetaMask Account 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.

MetaMask Advanced Settings

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.

MetaMask Set Custom Nonce

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.

MetaMask cancel transaction no gas customization

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.

MetaMask cancel transaction natively on the app

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-4: Before submitting the transaction, set the custom nonce to what you found in Step-2 and set a high gas price. You can look it up on ETH Gas Station or Gas Now.

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.

Also see:

Learn how to speed up your MetaMask if it is slow

Learn how to buy fractions of Ether to pay for gas

Originally published at BTC Geek

How do you rate this article?


14

1

btcgeek
btcgeek

Crypto research analyst since 2013


DeepResearch
DeepResearch

Deep dive into the world of cryptocurrency, DeFi tokens, crypto-assets, NFTs, and more

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.