1

Just wanted to ask about something weird that I keep running into:

I've been deploying smart contracts on Ethereum through truffle, and the estimated deployment cost during the --dry-run (simulation) is always different than the actual, live, non-dry-run deployment.

Anybody know why that is, out of curiosity?
Gas units used seems to be different between the simulation and the actual live deployment.

For example, for the same compiled contract, here's the results of my latest one:

Migrations dry-run (simulation)
===============================
> Network name:    'ethereum_live-fork'
> Network id:      1
> Block gas limit: 30000000 (0x1c9c380)

2_deploy_contracts.js
=====================

   Deploying 'MyContract'
   ---------------------
   > block number:        13587948
   > block timestamp:     1636539921
   > account:             0x0123
   > balance:             1.106993597391617736
   > gas used:            3721437 (0x38c8dd)
   > gas price:           100 gwei
   > value sent:          0 ETH
   > total cost:          0.3721437 ETH

Contract deployed at address: 0x0456
   -------------------------------------
   > Total cost:           0.3721437 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.3721437 ETH

And the actual deployment:

Starting migrations...
======================
> Network name:    'ethereum_live'
> Network id:      1
> Block gas limit: 29983726 (0x1c983ee)

2_deploy_contracts.js
=====================

   Deploying 'MyContract'
   ---------------------
   > transaction hash:    0xaAaBbB
   > Blocks: 7            Seconds: 112
   > contract address:    0x456
   > block number:        13587983
   > block timestamp:     1636540178
   > account:             0x123
   > balance:             1.065583597391617736
   > gas used:            4135537 (0x3f1a71)
   > gas price:           100 gwei
   > value sent:          0 ETH
   > total cost:          0.4135537 ETH

   Pausing for 3 confirmations...
   ------------------------------
   > confirmation number: 1 (block: 13587985)
   > confirmation number: 2 (block: 13587986)
   > confirmation number: 4 (block: 13587988)
   > Saving artifacts
   -------------------------------------
   > Total cost:           0.4135537 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.4135537 ETH

The difference of 0.04141 ETH is non-negligible. evmVersion in my truffle_config.js is petersburg.

2
  • Well, gas prices can fluctuate during the day (By A LOT). Might that be it?
    – Sky
    Nov 10, 2021 at 13:00
  • @sky both the dry run and the actual deployment transaction are broadcast at gas_price: 100 gwei. The difference lies in the different gas_limit supplied during the simulation and the live deployment, which truffle for some reason does - and I'd like to find out why :) Nov 10, 2021 at 13:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.