DEV Community

foxgem
foxgem

Posted on • Edited on

5

Troubleshooting: exceeds block gas limit

Symptom

Calling a contract method but getting the following error:

MetaMask - RPC Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32000, "message": "exceeds block gas limit"}}'
Enter fullscreen mode Exit fullscreen mode

The weirdest thing about this error is that the same calling succeeded before with the same contract, the same method, the same parameters, even the same wallet. But now, it fails.

Cause

Unlike other contracts calling failures, when you get this error, the tx is not actually sent on chain, the calling is rejected at the MetaMask level. So you don't see any information about tx or contract in the error message at all, only MetaMask.

The reason is because:

  • In Ethereumn, the block gas limit is different for each block. The value of the new block is determined by the algorithm and the miner vote. You can easily get this value with ethers.js: provider.getBlock('latest')).gasLimit.
  • If the gas limit of the sent tx is bigger than it, you get this error.

If the gas limit in your method is calculated on the fly, you may get this error.

Solution

Now that the cause has been found, the solution is simple: check the gas limit calculation and try to make it as accurate as possible, making sure it not exceeds the block gas limit.

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay