[Ethereum] the actual gasPrice used in a Truffle + Ganache environment
gasgas-pricetruffleweb3js
It doesn't seem to match the Ganache UI, nor web3 gas price.
Best Answer
The price of gas seems to be quite elusive in the ethereum world for a variety of reasons. In this context, it's because the supposed gasPrice isn't correct. The UI in Ganache and the value reported via web3 (and the value you set as the default on a contract in truffle tests for example) are all wrong. You have two options in the currently released versions: use the empirical value I've reported in this issue = 100000000000 OR manually set the gasPrice on each transaction.
EDIT: with EIP-1559 (shipped in London fork in July 2021) this is not true anymore.
I'm changing this answer to community wiki so that anyone can fix it (I don't really have time, sorry)
As explained in the Ethereum github's wiki the gas price is set by miners and the only way to guess the acceptable value is to look at the last block gas price. Then you look at the lowest and highest prices on the block and next block price should fit close to these values. Looking at more blocks in the past could give you a trend to guess if the price raises or goes down. But there is also a part of random, at least in Geth, so you can't exactly predict the gas price but only be close to the future block price. I think you can't be more accurate than geth gas price oracle.
If you do not set the gasPrice in a transaction it will use a default value (with testrpc appears to be 100 Gwei). It will not use the network gas price (returned by web3.eth.gasPrice). You have to explicitely set the gas price you want.
Best Answer
The price of gas seems to be quite elusive in the ethereum world for a variety of reasons. In this context, it's because the supposed
gasPrice
isn't correct. The UI in Ganache and the value reported via web3 (and the value you set as the default on a contract in truffle tests for example) are all wrong. You have two options in the currently released versions: use the empirical value I've reported in this issue = 100000000000 OR manually set thegasPrice
on each transaction.I'm using Ganache 1.0.1 and Truffle 4.0.5