[SOLVED] MetaMask - RPC Error: Internal JSON-RPC error after consecutive calls to a smart contract

Does anyone have a remedy for the “MetaMask - RPC Error: Internal JSON-RPC error.” aka “code: -32000, header not found” error, after consecutive calls (no gas) to a smart contract? I know this is a known metamask error, but I have not had to deal with it before. I have seen suggestions to implement a 100ms delay in between calls, but that does not seem to be doing the trick, and was looking for a more sturdy approach to the problem.

maybe it is an error from the speedy node directly, if you add 1s delay then it works fine?

After further testing, the delay is not working. But I am almost not seeing the error at all on Chrome, but I am seeing it very often on Brave

do you have same node RPC on both browsers?

Yes, I am using the one provided by my paid Moralis plan, but I have also tested other RPCs and am still getting the errors

This is the issue on the Metamask github that I am trying to work around, https://github.com/MetaMask/metamask-extension/issues/7234

are you on the same network on metamask that the rpc is on ?
if you are using the polygon mainnet rpc you have to be on the polygon network chain when executing ?

(https://github.com/MetaMask/metamask-extension/issues/7234#issuecomment-602986794)
you can see an example here

maybe you have different versions of metamask on those two browsers

Yes I am using the Polygon mainnet rpc on Polygon mainnet

I have Metamask v10.9.3 on both

I put back the 100ms delay and changed RPCs to https://polygon-rpc.com/ and I haven’t gotten the error since :upside_down_face:

Maybe it is something with speedy nodes, I switched back to my speedy node RPC and got the error a few times. Switched back to https://polygon-rpc.com/ and haven’t seen it once. (kept the delays in)

Solution:

Changing all get calls to using my custom speedy node as the JsonRpcPrivider instead of relying on the rpc in metamask (Web3Provider) to make the calls fixed the problem completely.

const provider = new ethers.providers.JsonRpcProvider("<speedyNodeUrl>");

const instance = new ethers.Contract(<contractAddress>, <abi>, provider);
const data = await instance.getCall();
2 Likes

Hello,how you edit that code?
I have same trouble here
Execution reverted
Bep20 error
I can not sent token from wallet metamask to another exchange

Hi, @Hansken Please create a new post with your question.