Jun 112020

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 Etherscan Gas Tracker 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.

MetaMask Account Settings

Step-2: Under Settings, click on Advanced Settings. Then find the setting that says: “Customize transaction nonceTurn 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.

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.

Related: Learn how to speed up your MetaMask if it is slow

Learn how to buy fractions of Ether to pay for gas

Tip: 0x5109110A484D4E20e1e5f5E94dc9620d7DD0819E

  11 Responses to “How to Set Nonce in Metamask”

  1. dont have this advanced option on iOS. please help!

    • Never used the iOS app, sorry! One way would be to import your key into a desktop version on Chrome or Brave and trying then. Otherwise, try asking the MetaMask team.

  2. Thank you this is very helpful. However my metamask fees for rarible still seem to be $124 pre NFT. I’ve looked at gas fees and even at an optimal time this happens. I’ve played with nonce settings,,,either using is as set (standard settings) or the 10000 you have above) and making it lower but it still doesn’t work. Any advice please? Thank you!

    • You can’t lower fees by changing the nonce. Also, don’t lower the gas limit. This can cause the transaction to fail and also use up all the ETH. Unfortunately, fees on Ethereum are high currently. The gas tends to be lower on the weekends, so you can try then. Check the current gas price on GasNow.

  3. What happens when I am trying to withdraw my matic from the Easyfi lending platform and my transaction has completed but my stuff is still staked? (I made prob 30 transactions in two days trying to pull out this coin.oops) but all transactions are saying completed.Can you help me?

    • That seems something specific to the app that you’re using on Matic. Matic transactions are fairly quick so the app should have been notified of the transaction if it is completed. Your best bet is probably to contact the app team on Discord. I am not familiar with Easyfi lending

  4. Thank you for the article! Unfortunaly I can’t see the nonce option even if I accept “Customize transaction nonce” in the metamask settings. Is there stmh else to do? I really don’t know what I am doing wrong

    • Ok nevermind.. after spending the last hours on trying to solve my error and after writing this message to you, I decided to reset my metamask acc. Now it works! 😉

      • Yeah it can be buggy like that. I’d try the rest account option and sometimes the good ol’ close the browser and open it or disable and re-enable the extension. Glad it’s working now

  5. Hi,

    I tried to buy a domain on ENSdomain through metamask, but I can’t sign the transaction with my ledger so all my transactions are being queued (7 actually, I did it multiple times because I didn’t understand directly the problem).
    I’d like to cancel all those transactions but I can’t see the nonce of the first on the line, and there’s no hash I can check on etherscan…
    How can I solve my issue please ?

    Many thanks

    • Adam, if you don’t see the transaction hash on Etherscan, that means the transaction is not yet submitted to the Ethereum network. You can safely remove your Metamask cache and retry the transactions.

      For ledger, the best way might be to connect Metamask to ledger and then submit the transactions. Make sure that contract data is enabled on your ledger before attempting to submit smart contract calls via Metamask. Hope this helps.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



This site uses Akismet to reduce spam. Learn how your comment data is processed.