When I want to deploy a smart contract, I use the eth.estimateGas
before deploying my smart contract. This gave me 688180 Gas.
let bytecode = compiledContract.contracts['Document'].bytecode;
let gasEstimate = web3.eth.estimateGas({
data: bytecode
});
But somehow this estimation is false, and I have to set manually the gas to some value e.g. 4700000.
var myContractReturned = MyContract.new(param1, param2, {
from:mySenderAddress,
data:bytecode,
gas:4700000 // gasEstimate not working here},
function(err, myContract){....}
Using web3.eth.getTransactionReceipt
, I can see that the real cost was 817540 Gas. I know that the gas that is not used is automatically refunded, so there is no real problem but I'm curious to know why such a difference!
Thanks in advance!