estimateGas error

I’m getting Internal JSON-RPC error whenever I call the estimateGas function.

Libraries:

"@web3auth/base": "^8.12.2",
"@web3auth/coinbase-adapter": "^8.12.2",
"@web3auth/ethereum-provider": "^8.12.3",
"@web3auth/metamask-adapter": "^8.12.2",
"@web3auth/no-modal": "^8.12.3",
"@web3auth/openlogin-adapter": "^8.12.2",
"@web3auth/wallet-connect-v2-adapter": "^8.12.3",
"web3": "^4.11.1",

RPC: https://rpc.ankr.com/eth
Network: Ethereum mainnet
Provider: JWT login with OpenLogin
Login method: MetaMask wallet

Code:

const web3 = new Web3(provider as any)
const walletAddress = await getAddress()
const contract = new web3.eth.Contract(contractAbi, contractAddress)

const gasEstimated = await contract.methods
        . myMethod(
          params
        )
        .estimateGas({
          from: walletAddress
        })

Generally these errors are associated with your RPC Provider. However, I want to check if you are getting this issue while logging in via Metamask or any Social Login?

I’m getting this issue with all login methods (MetaMask, Social, and Email Login).

About the RPC, is there a way to fallback with Web3Auth? I’ve been switching RPCs to fix this kind of issue, but it keeps happening. I’ve already used https://mainnet.infura.io/v3/${infuraToken}, https://eth-mainnet.g.alchemy.com/v2/${infuraToken} and now https://rpc.ankr.com/eth.

Hey @felipe1
Thanks for the information. Let me check this further and get back to you.

Thank you @maharshi . This issue constantly happens and blocks the user from completing the transaction. Sometimes the estimateGas function works, but sometimes (most of the time) it does not.

Hey @felipe1, thanks for the feedback.

From what you’ve shared, it seems like the issue might be related to the stability of the RPC endpoints rather than your implementation or the login method, especially since it’s occurring across all login methods (MetaMask, Social, and Email).

Here are a few preliminary checks you can perform:

  1. Check Wallet Balance: Ensure that the account you’re using has sufficient ETH balance. Even though estimateGas is just a simulation, some RPC providers might perform checks that require a balance.

  2. Contract Method and ABI: To verify if the contract method and ABI are set up correctly, you can first use the call method before estimating gas. This will simulate the transaction without sending it and can help identify issues with the method or ABI. Also, tools like Etherscan or Remix IDE can be handy to cross-check your ABI and method signatures.

  3. Transaction Simulation: Ensure the transaction itself wouldn’t fail due to logic errors or state-related conditions in your contract.

Regarding your question about fallback options between different RPC providers, Web3Auth doesn’t currently offer an automated fallback mechanism within the SDK. However, you can manually switch RPC providers as you’re already doing, though I understand this isn’t ideal.

Thanks for the explanation.
To your points:

  1. I do have sufficient ETH balance
  • Everything works when I call the contract methods on Etherscan. The problem is that when using our app, without specifying the gas fees, I get an error saying I don’t have enough ETH for the gas. And when I try to call the estimateGas function, I get the Internal JSON-RPC error. But sometimes it does work (mainly on Arbitrum). So I don’t think there’s an issue with the contract/ABI, otherwise it would never work.
  • The call method doesn’t work for me. I get Returned error: execution reverted: 2.
  • I also checked some sample codes on the Web3Auth repository, and they manually set the max fees for gas (web3auth-pnp-examples/web-modal-sdk/blockchain-connection-examples/evm-modal-example/src/ethersRPC.ts at main · Web3Auth/web3auth-pnp-examples · GitHub)
  1. The transaction works fine on Etherscan and most of the time on Arbitrum,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.