Metamask: Critical error in gas estimation via Web3.js

The latest update to the Metamask wallet introduced a critical error that could result in significant gas costs for users when deploying contracts on the Ethereum network. The issue affects gas estimation, which is crucial for accurately tracking the execution costs of smart contract transactions.

The issue: -32000 Gas estimation error

When using Web3.js to interact with the Ethereum blockchain, Metamask provides an estimate of the gas costs required for a given transaction or operation. However, starting with version 2.0.5, a new error appeared in the wallet when attempting to perform gas estimation using this method.

Error: -32000

If you encounter the following code in the contract deployment script:

const gasAmount = await this.factory.methods.createContract(

Math.floor(newDate(contract.ExpirationDate).getTime() / 1000),

// ...

);

When attempting to run the gasAmount command, you may encounter the following error:

>
TypeError: EstimateGas failed

Impact on User Experience

Metamask: Metamask just started throwing a -32000 error for gas estimation via web3.js

The -32000 error can result in significant gas costs for users that may not meet the user’s expectations or budget. This issue can also cause frustration and increased stress during contract deployment, especially when users rely on Metamask for smooth transactions.

Conclusion

As a user of this code, you should be aware of this critical bug in gas estimation via Web3.js starting with Metamask wallet version 2.0.5. This issue affects users like you who have been using the code successfully for a long time.

To fix this issue, we recommend that you update your contract deployment script to use a different method to estimate gas costs, for example:

  • Ethers.js: A popular library for interacting with the Ethereum blockchain that provides accurate and reliable gas estimation.
  • ContractKit

    : An open-source library for building smart contracts on the Ethereum network that provides robust gas estimation capabilities.

Mitigation Strategy

To minimize the impact of this bug, you can do the following:

  • Update your code to use a different method to estimate gas costs.
  • Track gas estimates in real-time using Ethers.js or ContractKit.
  • Be careful when entering into contracts on the Ethereum network and verify the accuracy of gas usage estimates before deployment.

Next Steps

If you continue to encounter this error, please feel free to contact our customer support team for help or guidance. Our goal is to provide accurate information and help users like you navigate the complexities of developing smart contracts on the Ethereum blockchain.

Taking proactive steps to resolve this issue will help ensure a smoother user experience and reduce the likelihood of errors related to Metamask gas estimation.