TransWikia.com

Transaction underpriced at 5000000 gas but overpriced at 10000000

Ethereum Asked by Vasya on August 26, 2021

I’ve been developing a smart contract for a while on the Ropsten network using the Truffle framework, quite successfully. My truffle-config.js looks like this:

const path = require("path");
const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
  networks: {
    develop: {
      port: 8545,
      network_id: "*",
      host: "127.0.0.1"
    },
    ropsten: {
      provider: new HDWalletProvider(mnemonic, ropsten),
      network_id: 3,
      gas: 4000000 
    },
    "live": {
      provider: new HDWalletProvider(mnemonic, mainnet),
      network_id: 1,
      gas: 5000000
    }
  },
  compilers: {
    solc: {
      version: "^0.6.0"
    }
  }
};

Where "mnemonic" and "ropsten" are strings connecting to my account and to my Infura link respectively.

I believe it is time to deploy my smart contract to the Mainnet. After looking for a little while for ways to do this within the Truffle framework, I came upon the Truffle documentation:

https://www.trufflesuite.com/tutorials/deploying-to-the-live-network#configuring-truffle

I concluded that using network_id: 1 is how I get truffle migrate --network live to deploy my smart contracts to the Mainnet.

After running the aforementioned command with gas specified at 5000000 in the truffle-config.js, I get the following error:

Error:  *** Deployment Failed ***

"Migrations" -- transaction underpriced.

However, turning that up to 10000000, I get the following error:

"Migrations" could not deploy due to insufficient funds
   * Account:  0xffA1c53b18d864A6340adA628BdFF6651fa4E097
   * Balance:  111432174000000000 wei
   * Message:  insufficient funds for gas * price + value
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

What do you think is happening here? Is there some golden spot between 5000000 and 10000000 I should be looking for, and if so, how can I know beforehand what it is? Or is there something else I’m missing?

One Answer

Inside the networks section, update your truffle-config.js with something like:

gasPrice: 470000000000,

In truffle-config.js, gas refers to the maximum amount of gas you are willing to pay for the deployement of your smart contract.

Let's assume you contract costs 8 000 000 gas. With the current average gas price of 40 Gwei, the total deployement cost will be 8M * 40 = 320000000 Gwei = 320000000000000000 wei > 111432174000000000 wei (your account balance) .

When deploying to the mainnet you should always fix the gas price by yourself using a "gasPrice" field in your truffle-config.

Correct answer by clement on August 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP