0

Or can I set different values?

If I can set different values, then how will they be used in the system (i.e., what gas-price and gas-limit will apply in every transaction that I execute)?

Here is my present configuration (using the same values for Truffle and for Ganache):

Truffle:

module.exports = {
    networks: {
        development: {
            host: "127.0.0.1",
            port: 8545,
            network_id: "*",
            gasPrice: 100000000000,
            gas: 6721975 // gas limit
        }
    }
};

Ganache:

--port=8545
--gasPrice=100000000000
--gasLimit=6721975

Thank you!!!

3

TL;DR: Yes you can use the same value.

Here is why:

Ganache

Ganache is a local test Blockchain.

  • -l or --gasLimit is the block gas limit (total amount in gas unit that can fit in a block). Let's say for example your block gasLimit is 1000000, you would be able to fit only 10 transactions of 100000 gas units each.

  • -g or --gasPrice is the default price per gas unit in wei. If a transaction doesn't set the gasPrice, this default price is used to calculate the gas fee [fee=gasUsed*gasPrice].

Truffle

In truffle configuration, this is different:

module.exports = {
    networks: {
        development: {
            host: "127.0.0.1",
            port: 8545,
            network_id: "*",
            gasPrice: 100000000000,
            gas: 6721975 // gas limit
        }
    }
};
  • gasPrice represents the price you willing to pay per gas unit to deploy the contracts you have under this Truffle project. Using Ganache, you can set the almost any value I would imagine.

  • gas is the maximum number of gas unit the EVM can use to process the contract deployment transaction. If it's too low, the transaction would fail, if it's too high, the excess will be refunded but if the effective gas used is higher than the block gas limit, the transaction will fail.

Metamask

When a user interacts with the contract deployed above (using Truffle), he can choose the gasLimit and the gasPrice:

  • gasLimit: is the maximum number of gas unit the EVM can use to process the transaction. It is recommended to use the function estimateGas to setup the limit (that's what Metamask is doing by default).

  • gasPrice: represents the price you willing to pay per gas unit. It is recommended to check EthGasStation to estimate how long it would take to get a transaction mined. Of course higher is the price, higher is the chance to be mined quickly.

Same concept here as Truffle except it is not only for contract deployment and migration script but any kind of transaction (transfer, contract methods, contract deployment)

Summary

gas fee estimation (wei) = gasEstimation (or gasLimit) * gasPrice

gas fee effective (wei) = gasUsed * gasPrice

gasEstimation >= gasUsed

gasUsed <= blockGasLimit
  • 1
    Thank you for the very detailed answer!!! I know that I can use the same values, because I AM using the same values (in both Truffle and Ganache, as specified in the question). My specific question was actually: "If I can set different values, then how will they be used in the system (i.e., what gas-price and gas-limit will apply in every transaction that I execute)?". Would you be able to refer to this question as well? Thanks again :) – goodvibration Jan 22 at 11:57
  • Sorry if my answer is ambiguous. As mentioned, Truffle gasLimit and gasPrice aren't the same thing as Ganache gas and gasPrice. In Ganache, gas refers to the block size limit and gasPrice to the default gasPrice if a transaction is sent without gasPrice. While Truffle gasLimit*gasPrice is a maximum amount of gas fee you are willing to pay for the contract deployment only! Every transaction require a gasLimit which is often hidden because of the use of estimateGas function and gasPrice can be empty and if so will be set to Ganache gasPrice (default). – Greg Jeanmart Jan 22 at 14:59
  • "Truffle gasLimit*gasPrice is a maximum amount of gas fee you are willing to pay for the contract deployment only" - are you certain about this? In Truffle tests, we typically never specify gas price nor gas limit. Does Truffle leave them empty when sending the transaction to Ganache? Your statement above implies that it does, except for the case of contract.deploy. Is that correct? – goodvibration Jan 22 at 16:07
  • I'm not saying that Truffle sends the transaction without gasLimit and/or gasPrice. If empty, I believe Truffle defaults the value - for gasLimit with an estimate - see this post - for gasPrice with web3.eth.getGasPrice which should be equals to Ganache gas block limit --gasLimit but that might not be true all the time depends of the ganache block history > "gas price is determined by the last few blocks median gas price" – Greg Jeanmart Jan 22 at 16:38
  • But you are saying that it doesn't use the values provided in truffle-config.js... am I right? – goodvibration Jan 22 at 18:26

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.