Contract Deployment
Publishing bytecode to an address so the contract can be called by anyone.
Basically
You put a smart contract's code on a blockchain. The contract can then run there.
Key Takeaways
- Contract deployment sends compiled bytecode in a special transaction with no recipient address. The blockchain creates a new smart contract account at a deterministically computed address.
- Each byte stored on-chain costs 200 gas, so deployment costs scale with bytecode size. Ethereum's EIP-170 limits contracts to 24,576 bytes to prevent denial-of-service attacks.
- You can use direct deployment for simple contracts, factory contracts for repeated creation, CREATE2 for deterministic addresses across chains, and proxy patterns for upgradeability.
What Is Contract Deployment?
Contract deployment publishes a smart contract's compiled bytecode to a blockchain. Before deployment, the contract exists only as source code on a developer's machine. After deployment, it is a permanent, executable program at a specific on-chain address that can receive transactions, hold funds, and execute logic autonomously.
Ethereum and other EVM-compatible chains use a transaction with compiled bytecode in its data field and no recipient address. The network processes the transaction, executes any initialisation logic in the constructor, and stores the resulting runtime bytecode at a newly generated contract address. The deployed contract's code is immutable and cannot be changed or deleted unless the contract includes self-destruct or upgrade logic.
How It Works
Smart contract deployment involves several distinct steps. You start with source code and finish with a confirmed deployment transaction on-chain.
Compilation
Smart contracts written in high-level languages like Solidity or Vyper must first be compiled into EVM bytecode. A compiler such as solc for Solidity produces two key outputs.
The Deployment Transaction
A deployment transaction has one critical difference from a regular transaction: it has no to address. You use this to signal that the transaction creates a new contract rather than calling an existing one.
Address Computation
The standard CREATE opcode derives a contract address from two inputs: your address as the deployer and your current nonce, or transaction count. The formula is:
The nonce increments with each transaction. The same bytecode deployed from the same account produces different contract addresses on different chains when the nonce differs. CREATE2 was introduced to address this.
Gas Costs
Deployment gas costs have several components. You pay them when you deploy a contract.
A contract at the EIP-170 maximum size of 24,576 bytes costs approximately 4.9 million gas just for code storage, before constructor execution or calldata costs. High network congestion on mainnet can push these gas fees to hundreds of dollars.
Direct Deployment
Direct deployment is the simplest approach: you send a creation transaction directly from a wallet or deployment script. It suits one-off contracts that do not need to be replicated. Hardhat, Foundry, and Remix automate the process by compiling, constructing the transaction, and broadcasting it.
Factory Contracts
A factory contract is a deployed contract that creates other contracts. The factory's function call handles creation instead of each instance being deployed from an externally owned account. Protocols that need many identical contracts often use this pattern, and the Uniswap factory contract deploys each Uniswap trading pair.
CREATE2 for Deterministic Addresses
CREATE2 was introduced in the Constantinople hard fork in 2019. It computes the contract address from the deployer address, a salt value, and the bytecode hash rather than a nonce. The formula is:
None of these inputs depend on chain-specific state like nonces. CREATE2 lets you deploy the same contract to the same address on multiple chains, which is critical for cross-chain protocols and smart wallet systems where users expect a consistent address across networks.
CREATE2 also enables counterfactual deployment. Applications can compute a contract's future address and interact with it by sending funds before the contract is deployed. Account abstraction wallets use this pattern so your wallet address exists before any on-chain transaction occurs.
Proxy Patterns for Upgradeability
Deployed bytecode is immutable, so developers use proxy contracts to enable upgrades. A proxy stores state and delegates all calls to a separate implementation contract using the EVM's delegatecall instruction. An upgrade points the proxy to new implementation bytecode while preserving the contract's address and state.
The main proxy patterns include several designs. They build on the separation between proxy and implementation contracts.
Testnet to Mainnet Workflow
Production deployments follow a staged process. You use it to catch bugs before committing real value.
Source Code Verification
Developers verify their contracts on block explorers like Etherscan after deploying to mainnet. Verification requires the original source code, compiler version, and optimisation settings. The explorer recompiles the source, confirms that the output matches the on-chain bytecode, and displays readable source code publicly so users and auditors can inspect the logic they are interacting with.
Hardhat and Foundry are modern deployment tools that automate verification. Their built-in plugins submit source code to Etherscan's API immediately after deployment.
Multi-Chain Deployment
Protocols increasingly deploy to multiple chains as the ecosystem fragments across L1s, L2s, and rollups. Multi-chain deployment introduces several challenges.
Hardhat Ignition and Foundry scripts help manage these complexities with reproducible, scripted deployment pipelines. Deterministic addressing through CREATE2 is essential for protocols managing stablecoin contracts across many chains because it provides a consistent user experience, as discussed in research on multi-chain stablecoin deployment strategies.
Immutability
A contract's bytecode cannot be changed after deployment. Bugs in non-upgradeable contracts require a new deployment and user migration, which can be costly and disruptive. You therefore need thorough testing and auditing before deployment.
Constructor Errors
Constructor arguments are ABI-encoded and appended to the bytecode in the deployment transaction. Incorrect arguments, such as a wrong address or wrong decimal precision, create a permanently misconfigured contract. Constructor errors cannot be corrected after deployment, unlike regular function calls.
Front-Running
Deployment transactions sit in the public mempool before confirmation. Attackers can observe pending deployments and submit competing transactions. They can, for example, deploy a malicious contract at a predictable CREATE2 address before the legitimate deployer or front-run initialisation transactions on proxy contracts to seize admin control.
Size Limits
EIP-170 caps contract bytecode at 24,576 bytes, and contracts above this limit fail to deploy. Developers near the limit must use techniques like gas optimisation, library linking to deploy shared logic as separate contracts, or splitting functionality across multiple contracts. EIP-3860 also limits initialisation code, which runs during deployment, to 49,152 bytes.
Upgrade Risks
Proxy patterns solve immutability but introduce their own risks. Storage layout collisions between proxy and implementation contracts can corrupt state. Misconfigured access control can let attackers exploit unrestricted upgrade functions, and the added complexity of proxy architectures has been the root cause of multiple high-profile DeFi exploits.
The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.