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
gasLimitandgasPricearen't the same thing as GanachegasandgasPrice. In Ganache,gasrefers to the block size limit andgasPriceto the default gasPrice if a transaction is sent without gasPrice. While TrufflegasLimit*gasPriceis a maximum amount of gas fee you are willing to pay for the contract deployment only! Every transaction require agasLimitwhich is often hidden because of the use ofestimateGasfunction and gasPrice can be empty and if so will be set to Ganache gasPrice (default). – Greg Jeanmart Jan 22 '19 at 14:59gasLimit*gasPriceis 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 ofcontract.deploy. Is that correct? – goodvibration Jan 22 '19 at 16:07web3.eth.getGasPricewhich should be equals to Ganache gas block limit--gasLimitbut 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 '19 at 16:38truffle-config.js... am I right? – goodvibration Jan 22 '19 at 18:26truffle-config.js. But these values are optional. I was just explaining how Truffle calculates the default value if it's not specified in the config file... – Greg Jeanmart Jan 22 '19 at 18:59