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
Key Components
- Boilerplate structure required by the Solc compiler.
- Placement of state variables versus functions.
Practical Implementation
A Factory that deploys new Wallets.
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.
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
Interactive Visualization
See exactly how the EVM handles this code in memory, storage, and the stack.
Click Run to execute the simulation
Then use the step controls to navigate