Skip to content
Back to Curriculum
ADVANCED

Contract Deployment

Deploying a contract is a special transaction sent to the zero address. The data payload contains the 'Creation Code' (which includes the constructor logic) and the 'Runtime Code' (which lives on-chain). Contracts can also deploy other contracts using the `new` keyword or `CREATE2`.

Syntax Structure

Example.sol
Loading...

Key Components

  • Boilerplate structure required by the Solc compiler.
  • Placement of state variables versus functions.

Practical Implementation

A Factory that deploys new Wallets.

Practical.sol
Loading...

Core Concepts

Creation Code

The code that runs ONCE. Its job is to return the Runtime Code.

Runtime Code

The code that stays on the blockchain forever.

Nonce

For CREATE, address = hash(sender, nonce). For CREATE2, address = hash(sender, salt, code).

Mental Model

The Construction Site

Deployment is building a house. The **Creation Code** is the construction crew. They show up, set up the foundation (Constructor), build the walls, and then they leave. The **Runtime Code** is the house that remains. The construction crew is gone forever.

Under the Hood

`CREATE` opcode initializes a new account. It runs the init code. If the init code `RETURN`s some bytes, those bytes become the code of the new account.

CREATECREATE2CODECOPY

Gas Analysis

Deployment is the most expensive operation.

  • • Use Minimal Proxies (Clones) instead of deploying full contracts repeatedly.
  • • Remove comments and unused functions to shrink bytecode.

Security Risks

Constructor front-running.

  • ! If your constructor or initialization logic is not atomic or protected, someone might be able to intercept the deploy transaction.

Common Use Cases

Factory patterns (Spawning new pairs in Uniswap).
Deterministic addresses (CREATE2).
Minimal Proxies (Clones).

Interactive Visualization

See exactly how the EVM handles this code in memory, storage, and the stack.

Interactive Simulation
0 / 0
Loading...
Type Solidity code (v0.8.26) and click Run. Compiler loads on first use (~2MB).

Click Run to execute the simulation

Then use the step controls to navigate