How to Debug Metamask Errors? (Developer Edition)
By: Aliasgar Merchant
Tags: Blockchain, Blockchain Development, Metamask, Blockchain Technology

Metamask Error

Localhost Error

While developing a Dapp, for testing purposes, a local account with Ganache is used. When Metamask is connected to localhost 9545 and it throws error you can try:

Restarting Ganache, Restart Browser or restart computer. Also check Metamask configuration and prefer using “127.0.0.1" instead of local host. Another parameter recently added is Chain ID. I tried using hexadecimal number, it refused — but provides a number to use.

Wrong address error

When Dapp is loaded, Metamask is injected into the Javascript code and then Metamask prompts user for access of account address.

However, when Dapp finishes loading, Javascript code will resume and then an object is instantiated which points to the smart contract using libraries like web3 or ether.

If metamask is connected to wrong network you will grab a wrong address or no address for smart contract.

To solve this, you need to select the correct address and reload the web page.

Incorrect nonce error

Another error is transaction doesn’t have correct nonce.

Nonce — This is an integer that is incremented for every transaction. So say, 1st transaction has nonce 0, 2nd transaction has nonce 1 so on and so forth.

Metamask saves this value of nonce in its memory. If a user resets Ganache, his nonce is reseted in local Blockchain, however they are not updated in metamask.

Hence, when Metamask sends transaction, it throws an error because of the nonce mismatch.

Reset your metamask account. Setting → Advanced → Reset Account

Error in Solidity Code

Another error is when there is some error in Solidity code. In this case the transaction will fail without any popup from metamask.

This is because Metamask before sending a transaction estimates the cost of gas spent on the transaction and it anticipates if the transaction will be successful or not.

Debug the Solidity code

Did it run out of Gas?

Another common error with Metamask is ‘Did it run out of Gas?’ This could be due to two reasons.

a. The estimation of gas required by Metamask was wrong.

In that case you have to manually update the gas emit in confirmation popup of metamask.

b. You trigged an error in solidity code.

Debug the Solidity code

Response has no error or result for request

Last error is ‘Response has no error or result for request’ this happens when ganache is too slow to respond to metamask.

This happens when either ganache is not running or ganache isn't responding.

You can simply solve this by restarting ganache.

Ultimate Metamask Reset

Use this as the last weapon, when none of the above technique seems to be working and you need to completely reset metamask.

Follow the steps in the diagram illustrated below.

Metamask reset

Restart the local Blockchain. Write test for Smart Contract and make sure all of them passes. Deploy Smart Contract to local Blockchain Enviorment. Ganache is synchronized with Metamask.

For this, you can use mnemonic phrase from Ganache in Metamask. In Metamask, select correct network. Select correct account. Reset account. Reload the front-end by clearing cache.