How Contract Deployment Works
Deployment is a transaction like any other, with special rules. This lesson explains the contract creation transaction, how constructor arguments are passed, how CREATE and CREATE2 determine addresses and what deployment costs.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the contract creation transaction.
- Explain how CREATE and CREATE2 determine addresses.
- Identify the components of deployment cost.
- Explain how constructor arguments are passed.
The contract creation transaction
A contract is deployed by a transaction whose to field is empty. The following sequence shows what happens.
-
Build
The deployer's tool concatenates the creation bytecode and the ABI-encoded constructor arguments as the transaction data.
-
Execute
The EVM runs the creation code, which executes the constructor, initialising storage and immutables.
-
Return runtime code
The creation code returns the runtime bytecode.
-
Store
The network stores the runtime code at the new address and charges 200 gas per byte.
-
Report
The receipt's
contractAddressfield gives the new address.
If the constructor reverts or the transaction runs out of gas, no contract is created, but the gas used is still paid.
The following diagram shows the steps of a deployment and how the address is derived.

What a deployment does
Contract addresses
The address of a new contract is computed, not chosen. The following comparison shows the two methods.
new C() in Soliditynew C{salt: s}()Because a CREATE address depends only on the deployer and its nonce, the first contract deployed by a fresh account is always at the same address. On Hardhat Network, the first account's first deployment is always at 0x5FbDB2315678afecb367f032d93F642f64180aa3, which is why tutorials can hard-code it.
What deployment costs
Deployment is usually the most expensive transaction a contract sees. The following table breaks down the cost.
| Component | Gas |
|---|---|
| Base transaction cost | 21,000 |
| Contract creation | 32,000 |
| Creation code as calldata | 4 per zero byte, 16 per non-zero byte |
| Constructor execution | Varies; storage writes dominate |
| Code deposit | 200 per byte of runtime code |
A small contract of a few hundred bytes costs around 150,000 gas to deploy; a large DeFi contract near the 24,576-byte limit costs several million. At mainnet gas prices this can be significant, so teams measure deployment gas and may use the optimizer's low-runs setting or libraries to reduce code size.
Estimating deployment gas
Constructor arguments
A token's constructor is constructor(string memory name, uint256 supply). A developer deploys it with web3.js using contract.deploy({ data: bytecode }).send({ from }) and the transaction reverts or the token has an empty name. What is wrong?
The constructor arguments were not passed. They must be given as contract.deploy({ data: bytecode, arguments: ["Club Token", 1000000n] }), so that web3.js ABI-encodes them and appends them to the bytecode. The same arguments are needed later to verify the source.
Predicting an address
A deployer account has sent 4 transactions on Sepolia. Its next transaction will deploy a contract. Can the team know the contract's address before sending it?
Yes. The next nonce is 4, and the address is the last 20 bytes of keccak256(rlp([deployer, 4])); libraries provide helpers for this calculation. If any other transaction from the account is sent first, the nonce and therefore the address change.
Where does a deployer find the address of a newly created contract?
Show answer
In the transaction receipt's contractAddress field. It can also be computed in advance from the deployer address and nonce (CREATE).
Exam Tips
Remember for the exam
- Contract creation: a transaction with no to address, carrying creation bytecode and encoded constructor arguments.
- The receipt's contractAddress gives the new address.
- CREATE addresses depend on deployer and nonce; CREATE2 on factory, salt and code.
- Deployment pays 21,000 + 32,000 + calldata + constructor + 200 gas per byte of code.