0

I was just trying to deploy a new contract on the Ethereum MAIN-Net (not Ropsten, Rinkeby or the other test-nets) - and I’m getting this strange error:

Message:  sender doesn't have enough funds to send tx.
The upfront cost is: 159840000000000000 and the sender's account
only has: 158236521250000000

The reason I’m finding this strange is cause while I do indeed have only 0.158 ETH in my account - about $21.60 using today’s rate, which of course isn’t much, those funds should still be plenty enough for simple contract deployments. Especially considering the following:

-I deployed this very same contract - successfully - to:

  1. My local Development Network (Ganache) - where the Total Cost came back at 0.01332576 ETH (about $1.80)
  2. The Rospten Network - where Total Cost came back at 0.01342176 ETH - about $1.83

While I know there's obviously going to be a difference between the various test-nets and the REAL Ethereum Blockchain, it can’t really be like $2 on one and more than $21 on the other, can it? That’s like 1,050% higher.

Is there some other thing going on here that I'm not aware of?

Would really appreciate any insights into what's causing this.

=================================

UPDATE:

As per @smarx suggestion, I'm adding some code & context:

TOOLS:
-I'm using Truffle to deploy my contracts.
-Running ganache locally on my MacBookPro
-Running Truffle Version returns:

Truffle v5.0.4 (core: 5.0.4)<br/>
Solidity v0.5.0 (solc-js)<br/>
Node v11.10.0<br/>

Here's my deploying code - my truffle.json file.

require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider');


module.exports = {
    networks: {
        mainnet: {
            provider: function () {
                return new HDWalletProvider(
                    process.env.PRODUCTION_MNENOMIC,
                    "https://mainnet.infura.io/vs/${process.env.INFURA_API_KEY}",
                    15
                )
            },
            from: "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            network_id: 1,
            gas: 7992000,
            gasPrice: 20000000000,
            confirmations: 2
        },
        ropsten: {
            provider: function () {
                return new HDWalletProvider(
                    process.env.DEV_MNENOMIC,
                    "https://ropsten.infura.io/${process.env.INFURA_API_KEY}"
                )
            },
            network_id: 3,
            gas: 8000000,
            gasPrice: 20000000000
        },

        development: {
            host: "127.0.0.1",
            port: 8545,
            network_id: "*" // Match any network id
        },
    },
    solc: {
        optimizer: {
            enabled: true,
            runs: 200
        }
    }
}

As mentioned before, this code worked perfectly on both my local Ganache deployment as well as my remote Ropsten deployment. I also used this exact same code successfully in the past - as in last week - to deploy contracts to mainnet, so I know it has worked and is good for at least some deployments - and I thought it'd be for all of them.

Hope this sheds a lot of light. If more info is needed, please let me know specifics.

======================

UPDATE#2 - thought I'd throw in the exact copy of the error truffle is giving me:

1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
Error:  *** Deployment Failed ***

"Migrations" could not deploy due to insufficient funds
   * Account:  0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   * Balance:  158236521250000000 wei
   * Message:  sender doesn't have enough funds to send tx. The upfront cost is: 159840000000000000 and the sender's account only has: 158236521250000000
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:364:1
    at processTicksAndRejections (internal/process/next_tick.js:81:5)
Truffle v5.0.4 (core: 5.0.4)
Node v11.10.0
  • Are we supposed to just guess? You haven't shared anything at all that would help. – smarx Mar 10 at 19:15
  • I thought I shared everything that was pertinent, but I'd be happy to share anything you might deem necessary. Can you give some specifics of what you might like to see? – Sirab33 Mar 10 at 23:09
  • Your code? Or if you're not deploying with code, the name of the tool you're using? The values you're supplying for the gas limit and gas price? Imagine someone else asked you this question, and think of the first handful of questions you'd ask. Then answer those. – smarx Mar 10 at 23:11
  • Maybe a good start would be where you're seeing the error message you shared. – smarx Mar 10 at 23:12
  • @smarx I updated the question as per your suggestion. – Sirab33 Mar 10 at 23:23
3

The values in your config for mainnet are 7992000 gas limit and 20000000000 gas price, which leaves a tx price of 0.15984 ETH, which your account doesn't have enough for. A tx with a gasPrice*gasLimit+value higher than the accounts balance can't be mined, as it wouldn't have a high enough balance. Try lowering the gas limit to 7000000.

  • @ flygoing ok, I was just about to try what you suggested - but then I thought: wait a minute, are you actually telling me that this deployment - of what is a pretty straight forward contract - actually COULD cost me around $20??? That seems crazy. I mean this sort of pricing - its just plain prohibitive. – Sirab33 Mar 11 at 0:28
  • I honestly don't remember where I originally got those numbers I'm using (7992000 gas limit and 20000000000 gas price) - and yet they are the thing that's ultimately dictating the price - which seems quite inflated. So is there some reliable tool out there that can estimate the TRUE cost of deploying my contract that I could use to set good working values? Values that will be both high enough to ensure deployment - but also not too high so that I don't overspend? – Sirab33 Mar 11 at 0:33
  • It could cost $1000 if you set a really high gas price. It'll only actually cost $20 in the original example if it used all 7992000 gas you let it use, which would only happen if it's a large contract or you're setting a lot of state in the constructor.. Your gas price is also 10x higher than the current average on ethgasstation.info, so you can just lower that to 2000000000 as well. – flygoing Mar 11 at 1:03
  • That's just how pricing works. A miner picks the transactions to mine by sorting them by gas price. Gas limit is just 21k for normal sends, and you can also estimate the gas for contract calls by calling estimateGas in web3.js. You can use ethgasstation.info to get the gas price to use (also convert from gwei to wei, since that's what the value in the config is in). – flygoing Mar 11 at 1:05
  • 1
    Hey that worked! My contract is deployed. Many thanks - will give you credit for right answer. Cheers! – Sirab33 Mar 11 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.