6

In order to achieve a no-coin bootstrapping of my private network I'm trying to deploy a first special contract having zero funds in owner wallet (every wallet of this private network should have zero balance) and to do so with truffle, gasPrice was set to 0 on truffle.js config file.

Nevertheless, when deploying truffle Migrations contract the following error is thrown:

"Migrations" could not deploy due to insufficient funds
* Account:  0x5FBF29a8Ad77EA087275858d874AcD55526cFbDF
* Balance:  0 wei
* Message:  sender doesn't have enough funds to send tx. The upfront cost is: 9400000000000000 and the sender's account only has: 0

The question is: how can be 9400000000000000 the expected cost while gasPrice being 0. Shouldn't cost be 0 too?

Some tests on the node console show that even setting flag gasPrice to 0 on the miner simple transactions having gasPrice=0 are not mined. So probably the problem is not on deploying contracts but simply transacting with zero cost.

truffle.js:

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

module.exports = {
    networks: {
    development: {
        gas : 4700000,
        gasPrice : 0,
        provider: function() {
        return new HDWalletProvider(mnemonic, "http://127.0.0.1:port...", 0, 10)
        },
        network_id: "*" // Match any network id
    },
    ropsten: {
        gas : 4700000,
        gasPrice : 10000000000,
        provider: function() {
        return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/...", 0, 10)
        },
        network_id: "*" // Match any network id
    }
    },

    compilers: {
    solc: {
        version: "0.4.24",
        docker: false,
        settings: {
        optimizer: {
            enabled: true,
        }
        }
    }
    }
};
  • 1
    can you post your truffle.js config file? – MSwezey Mar 15 at 20:55
  • 1
    I do not know the answer, but my gut feeling that a lot of Ethereum tooling has been hardwired for a real gas cost and you need to fix things here and there if you want to run without gas at all. – Mikko Ohtamaa Mar 19 at 10:03
3
+50

Truffle default gas-price is 20000000000 wei.

You can see it in the source code:

var default_tx_values = {
  gas: 6721975,
  gasPrice: 20000000000, // 20 gwei,
  from: null
};

When you set gasPrice: 0 in your Truffle configuration file, the default value is used instead.

You can observe it by adding the following printout in your migration script:

  • console.log(web3.eth.gasPrice), if you're using Truffle v4.x (Web3 v0.x)
  • console.log(await web3.eth.getGasPrice()), if you're using Truffle v5.x (Web3 v1.x)

If you multiply this default gasPrice by your gas configuration, you will get:

20000000000 * 4700000

Which without putting into a calculator, I am guessing to be equal to 9400000000000000.

Please note that in the official documentation, they tell you:

  • gas: Gas limit used for deploys. Default is 4712388.
  • gasPrice: Gas price used for deploys. Default is 100000000000 (100 Shannon).

Which used to be true in earlier versions of Truffle, but in the current version it stands at 6721975 and 20000000000 respectively (as I quoted above, directly from the source code).

UPDATE:

All the details above are accurate, however, the reason for gasPrice being 20000000000 is not because it is Truffle's default configuration, but because it is Ganache's default configuration. I'm taking a wild guess here that the provider on your private network is indeed Ganache...

  • Thx! you said "the default value is used instead", why is that? Is it because gasPrice cannot be 0? How can I force truffle to use gasPrice=0 instead of default value? – Juan Ignacio Pérez Sacristán Mar 21 at 17:29
  • @JuanIgnacioPérezSacristán: You're welcome :) I'm not really sure why they chose to prevent gasPrice:0. Perhaps because it's not feasible on the mainnet. You can use gasPrice:1, I'm pretty sure that it will allow you to achieve your goal for that matter (side note: I think you need to set it on the provider side, i.e., on ganache-cli in the case of truffle test, and on testrpc-sc in the case of solidity-coverage). – goodvibration Mar 21 at 19:01
  • 1
    @JuanIgnacioPérezSacristán: Thinking over it again, it is possible that although all the details in my answer are accurate, the reason for gasPrice being 20000000000 is not because it is Truffle's default configuration, but because it is Ganache's default configuration. However, I cannot say for sure, because you did not specify which provider you are using for your private network. Is it indeed Ganache? If it is, then you can set gasPrice:0 there. – goodvibration Mar 21 at 19:17
  • Thx, it is not Ganache. On port 8546 I'm running an Ethereum geth node – Juan Ignacio Pérez Sacristán Mar 22 at 8:59
  • Having Truffle v5.0.3, console.log(await web3.eth.getGasPrice()) is not working: "SyntaxError: missing ) after argument list". It seems like await is the problem. Also tried console.log(web3.eth.gasPrice), but result was undefined – Juan Ignacio Pérez Sacristán Mar 22 at 9:14
0

gasPrice should be a string (allowing it to be 0!) https://github.com/trufflesuite/truffle/issues/680

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.