Cost to Deploy a Contract on the Ethereum Network

The cost of your deployment is based on 5 things, with a 6th affecting the estimated cost of deployment:

  1. The flat fee of 32k gas. The CREATE op code, which is called during contract creation, costs a fixed 32k gas. This is of course on top of the 21k gas of a normal tx. Note: During contract creation from an EOA (non-contract address), the CREATE opcode isn’t explicitly called. The return value of the tx is actually used to create the contract, but the fixed 32k fee is the same.
  2. The amount of bytecode in the compiled contract. More bytecode means more storage, and each byte costs 200 gas. This adds up very quickly. Note that inherited parent contracts are also included in the bytecode.
  3. The TX data. All the bytecode your sending as tx data costs 68 for non-zero bytes and 4 for zero bytes.
  4. The code actually runs before creation of the contract, e.g. the constructor of the contract. If the constructor requires a lot of computation to generate the bytecode, then it’ll be even more expensive.
  5. The gas price. The higher gas price you use, the higher it will cost. See  ethgasstation.info (Now: https://www.useweb3.xyz/gas)  for good gas prices to use right now. At the time of writing, 2 gwei is a quick gas price to use.
  6. Gas limit. Let whatever tool you’re using for deployment estimate this for you, and then bump it up some. It’ll return the unused gas, but just make sure you supply at least how much gas it needs or it will fail and you will still pay for the gas.

Overall if you were deploying a contract with a simple constructor and 5k bytes of compiled bytecode, you’d be paying roughly:

CREATE 32k

TX 21k

CONTRACT CODE 5k*200 

ESTIMATED NON-ZERO TX BYTES 5.5k*(.95*68) 

ESTIMATED ZERO TX BYTES 5.5k*(.05*4)

CONSTRUCTOR 1k

This comes out to ~1.41 million gas, which is less than $5 USD right now. Gas prices were 20x what they are now a couple weeks ago, so you could have paid $100 for the same contract creation.

You can read more about the bytecode based costs in the yellow paper