Error: insufficient funds for gas * price + value

Hi, I’ve already asked this before on this topic but the same issue is happening again. This time, it only happens with wallets created by Web3Auth. 3rd party wallets (such as MetaMask and Coinbase Wallet) are working fine.

I’ve tested with different accounts with enough ETH for gas on Ethereum Mainnet and Arbitrum, but I still receive the same error.

{
    "jsonrpc": "2.0",
    "id": "t0i4i298l4",
    "error": {
        "code": -32000,
        "message": "insufficient funds for gas * price + value: address 0xF0b13b30E4F3F989a717E6c464dAcF8D438b3823 have 50000000000000000 want 2695404381981239840000000"
    }
}
"code": -32603,
  "message": "Internal JSON-RPC error.",
  "data": {
    "code": -32000,
    "message": "insufficient funds for gas * price + value: balance 9505553116391833, tx cost 15186812986400000, overshot 5681259870008167",
    "cause": null
  },
"@web3auth/base": "^8.8.0",
"@web3auth/coinbase-adapter": "^8.9.1",
"@web3auth/ethereum-provider": "^8.10.2",
"@web3auth/metamask-adapter": "^8.8.0",
"@web3auth/no-modal": "^8.10.2",
"@web3auth/openlogin-adapter": "^8.8.0",
"@web3auth/wallet-connect-v2-adapter": "^8.6.2",

Hey, can you please the web3 package you are using to interact with blockchain? Also, which contract you are interacting with? We are a key management solution, so we don’t do the gas estimation. Also can share how are you doing the gas estimation?

We are using web3: 4.11.0, and the contract on testnet is https://sepolia.etherscan.io/address/0x7D0E98f301f21a44e9882978355a83b513F611F0.

This is how we are doing the gas estimation:

const ethPriceInUsd = ethCurrency.valueInUSD
const maxTxnCostUsd = 50
const maxTxnCostEth = maxTxnCostUsd / ethPriceInUsd
const maxTxnCostWei = web3.utils.toWei(maxTxnCostEth.toString(), 'ether')
const gasLimit = 550000
const gasPriceWei = BigNumber(maxTxnCostWei).dividedBy(gasLimit)
const gasPriceGwei = BigNumber(gasPriceWei).dividedBy(1e9)

const gas = gasLimit.toString()
const gasPrice = web3.utils.toWei(gasPriceGwei.toString(), 'gwei')

What is intriguing to us is that the issue only happens if we sign in with any social or email account. If we sign in with a 3rd party wallet directly, everything works. Also, this solution was working fine until a few days ago.

The first thing I see is you are setting the maxTxnCostUsd hardcoded, along with gasLimit. For gas limit you should always do the runtime estimation using the API. You can checkout the docs here: web3.eth.Contract — web3.js 1.0.0 documentation

Same for maxTxnCostUsd, you can get the gasPrice on runtime using the RPC. For the 3rd party, they do calculate it for you, that’s why issue might not be happening.

const gasEstimate = await contract.methods
        .myMethod(params)
        .estimateGas({
   from: walletAddress,
   value: amount
});

When I call the estimateGas method I receive Internal JSON-RPC error. Do you have any idea why?

Hey @felipe1

Which RPC URL are you using when initializing Web3Auth?

I’ve tried https://mainnet.infura.io/v3/${infuraToken} and https://eth-mainnet.g.alchemy.com/v2/${infuraToken}

Ok, thank you for sharing. Can you test using a public RPC from Ankr just once?

In the meantime, I will test Alchemy’s and Infura’s RPC in a demo app.

And I see that you’re not using the latest SDK, please update that to latest.

Also, this says the actual error message.

What’s your balance?

I’ve tested with wallets with $50 and $500 in ETH

Just to confirm you have added these funds on the wallet generated by web3auth using your social login right?

Yeah, that’s correct

I was trying to reproduce this issue on the same version of web3 (v4.11.1) and web3auth v8.12 (latest)

With 0.1 Sepolia Eth Balance and the following function from our examples:

const sendTransaction = async (provider: IProvider): Promise<any> => {
  try {
    const web3 = new Web3(provider as any);

    // Get user's Ethereum public address
    const fromAddress = (await web3.eth.getAccounts())[0];

    const destination = fromAddress;

    const amount = web3.utils.toWei("0.001", "ether"); // Convert 1 ether to wei
    let transaction = {
      from: fromAddress,
      to: destination,
      data: "0x",
      value: amount,
    }

    // calculate gas transaction before sending
    transaction = { ...transaction, gas: await web3.eth.estimateGas(transaction) } as any;

    // Submit transaction to the blockchain and wait for it to be mined
    const receipt = await web3.eth.sendTransaction(transaction);

    return JSON.stringify(receipt, (key, value) =>
      typeof value === 'bigint'
        ? value.toString()
        : value // return everything else unchanged
    );
  } catch (error) {
    return error as string;
  }
}

The transaction went through without any issue. Can you check the same?

Yeah, so I never reproduced the issue on testnet (sepolia and arbitrum sepolia). It was always on mainnet and with a wallet generated by Web3Auth.
However, I just updated the RPC to the one from Ankr and it worked.

How can that be possible? Since I was using a very well-known RPC.

Can I know the provider? I would like to test locally to find out the root cause of it. Additionally with Metamask and other similar wallets, the fallback is set to the Infura RPCs, there might be a chance that your particular RPC provider was not being used there as well.

I’m using JWT login with OpenLogin.
Also, is there a way to fallback the RPC with Web3Auth?

Just following up. Is there a way to fallback the RPC with Web3Auth?
Also, would you know why I get Internal JSON-RPC error. when I call the estimateGas method?

const gasEstimate = await contract.methods
        .myMethod(params)
        .estimateGas({
   from: walletAddress,
   value: amount
});

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