3

I can't get my contract to deploy successfully using Infura, MetaMask, and Truffle.

When I run truffle migrate --network live I get this error:

Error encountered, bailing. Network state unknown. Review successful transactions manually. insufficient funds for gas * price + value

But then, if I run truffle migrate --network live --dry-run I get this output:

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

Assuming that value is in wei, why would it cost so much to deploy a contract? What can I do about this?

Here is my truffle.js file:

var HDWalletProvider = require("truffle-hdwallet-provider");

var mnemonic = "my_mnemonic";

module.exports = {
  networks: {
    live: {
      network_id: 1,
      provider: new HDWalletProvider(mnemonic, "https://mainnet.infura.io/my_api_key")    
    }   
  }
};
9
  • Are you sending ether at deploy time as well? It would help if you posted your code. Commented Feb 24, 2018 at 18:42
  • @AdamKipnis Nope. Good point, I posted my contract's code. Commented Feb 24, 2018 at 19:00
  • 1
    @vipertherapper unrelated to your question, but unless you use msg.value in a function, you shouldn't make that function payable. That keyword means that you can send ETH to the contract with the transaction, but your returnEth, and fee don't do that - only adopt expects ETH to be sent to it
    – Andrey
    Commented Feb 24, 2018 at 19:07
  • @Andrey thanks for pointing that out. So I should just remove payable from returnEth and fee? What are the implications of leaving the payable keyword in those functions? Commented Feb 24, 2018 at 19:09
  • The implications are that someone can send eth when calling those functions, and that eth will be stuck in the contract, as the contract has no way of returning it back to the caller or the owner
    – Andrey
    Commented Feb 24, 2018 at 19:12

1 Answer 1

1

You can use remix.ethereum.org to test your contract and calculate gas usage. For me it uses 2M gas approx when deploying.

You did not specify the gas limit in your config it will use de default (it was around 6.7M gas). You can try lowering it in your truffle.js.

var HDWalletProvider = require("truffle-hdwallet-provider");

var mnemonic = "my_mnemonic";

module.exports = {
  networks: {
    live: {
      network_id: 1,
      provider: new HDWalletProvider(mnemonic, "https://mainnet.infura.io/my_api_key"),
      gas: "4000000",           // 4M
      gasPrice: "20000000000"   // 20gwei
    }   
  }
};
2
  • I thought the same thing, but the same error (with the same cost) is thrown regardless of the gas/gasPrice set in truffle.js. Plus, even with those parameters, the cost should be much less (total <.03 eth @20 Gwei). Commented Feb 24, 2018 at 19:22
  • @AdamKipnis I'd have to agree with you. I'm at a loss here. I'm trying to understand why this is happening. Commented Feb 24, 2018 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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