In zkEVM, I calculated the gas fee based on gas price (3 GWEI) and gas limit (3M), but the transaction still failed with insufficient funds. What can I do?

Created by Kenil Shah, Modified on Wed, 18 Sep at 11:25 PM by Kenil Shah

The discrepancy between the calculated gas fee and the insufficient funds error could be influenced by factors like network congestion or higher gas prices. To address this, consider increasing the gas price to a higher value when deploying your contracts, especially during periods of high network activity. This ensures your transaction is prioritized and executed successfully.


Additionally, double-check that your address is correctly funded with the expected balance, and confirm that you are specifying both the gas limit and gas price appropriately during contract deployment.


To help you estimate the gas limit and gas price more accurately, here's a code snippet using ethers.js v6:


import { ethers } from "ethers";

// Polygon zkEVM RPC URL
const zkEvmRpcUrl = "https://zkevm-rpc.com";

// Create a provider for the zkEVM network
const provider = new ethers.JsonRpcProvider(zkEvmRpcUrl);

async function getGasPrice() {
  try {
    // Fetch the current gas price in wei
    const gasPrice = await provider.getGasPrice();
    
    // Convert gas price from wei to gwei
    const gasPriceInGwei = ethers.formatUnits(gasPrice, "gwei");

    console.log(`Current gas price on Polygon zkEVM: ${gasPriceInGwei} gwei`);
  } catch (error) {
    console.error("Error fetching gas price:", error);
  }
}

getGasPrice();



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article