# Contract transaction: Gas estimated doesn't fit gas used

After finding out how to estimate contract tx fees thx to How to estimate the cost to call a Smart Contract method? and Syntax for calling contract state changing methods I tried to use all that knowledge and implement my own contract transaction with previous gas estimation, but they differ quite a lot. Gas estimated is 27,348 meanwhile Gas consumed is 181,080. So, what is wrong? Is this gas estimation process well done when dealing with smart contracts?

This is the data I used to estimate the gas for the endpoint: "start(address, address)" in a Smart Contract with address 0x27c042342C9ba937214117e11A4970A6145034cB

``````web3_sha3(endpoint) = 0xaa6d19c0b1d22f6983033c255695177ad1db0a0aad0435b6f6a367b48d4b37f4
arguments = "0xa7e3c7c227c72a60e5a2f9912448fb1c21078769, 0xf28dafbfeb41bf32869c9d498da0d651d0206ed4"
strhex(arguments) = 0x3078613765336337633232376337326136306535613266393931323434386662316332313037383736392c20307866323864616662666562343162663332383639633964343938646130643635316430323036656434
data = 0xaa6d19c03078613765336337633232376337326136306535613266393931323434386662316332313037383736392c20307866323864616662666562343162663332383639633964343938646130643635316430323036656434
``````

yielding a Gas estimation of: 27,348

On the other hand, following tx is performed:

``````sc.start.sendTransaction("0xa7e3c7c227c72a60e5a2f9912448fb1c21078769", "0x47978a69f410d0f61850c92acdb0d4c464d70937", {from:"0x3b877e80b5c0b29d88f3768ed4292b35fdd93a9d", value:"0x55ae82600", gas:1000000});

``````

and once the tx has been mined this is the resulting gas values:

``````Gas: 1,000,000
Gas Used By Transaction: 181,080
``````

So, why estimated gas is so off? Thx in advance!

• Different code paths taken during the estimate and the one that gets mined? It also seems the 2nd argument in the sendTransaction is different from the one provided in the estimate. ethereum.stackexchange.com/questions/266/…
– eth
Oct 14, 2016 at 16:05

I have found something, maybe it could help others...

I've also found very valuable info about passing parameters to contracts on https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI#examples

Now, it works like a charm!

``````endpoint = "start(address,address)"
web3_sha3(endpoint) = 0x3ccfe887556b4c598501287bcd4528f0b8830f303e150d3b4c3ac9831b7989a8
arguments = Array (
(
[value] => 0xa7e3c7c227c72a60e5a2f9912448fb1c21078769
)