0x4e59b44847b379578588920ca78fbf26c0b4956c
Deployment Status: Default preinstall
Gas Cost: Deployment cost + ~32,000 gas overhead
Key Features
- Deterministic Addresses: Compute contract addresses before deployment
- Cross-chain Consistency: Same address on all chains with the same bytecode and salt
- Minimal Implementation: Only 45 bytes of optimized assembly code
- No Storage or State: Pure function contract with no storage variables
How It Works
The CREATE2 opcode computes addresses using:- Pre-funding of contract addresses before deployment
- Cross-chain address consistency
- Gasless contract deployment patterns
Usage
Deploy a Contract
Compute Deployment Address
You can calculate the deployment address without actually deploying:Common Use Cases
Cross-chain Deployments
Cross-chain Deployments
Deploy contracts to the same address across multiple chains:
Counterfactual Interactions
Counterfactual Interactions
Interact with contracts before they’re deployed:
- Compute the future address
- Send funds or tokens to that address
- Deploy the contract later when needed
Upgrade Patterns
Upgrade Patterns
Predictable upgrade addresses using versioned salts:
Factory Patterns
Factory Patterns
Build factory contracts with deterministic child addresses:
Implementation Details
The Create2 factory contract is extremely minimal:- Reads the salt (32 bytes) and bytecode from calldata
- Uses the CREATE2 opcode to deploy the contract
- Returns the deployed contract address
Best Practices
Security Considerations:
- Always verify bytecode integrity before deployment
- Be aware that anyone can deploy to a CREATE2 address if they have the bytecode and salt
- Consider using access controls in your factory contracts
Salt Selection
Choose salts carefully for your use case:Gas Optimization
- The Create2 factory adds ~32,000 gas overhead
- Batch deployments in a single transaction when possible
- Pre-compute addresses to avoid on-chain calculations
Comparison with CREATE
Aspect | CREATE | CREATE2 |
---|---|---|
Address Calculation | Based on deployer + nonce | Based on deployer + salt + bytecode |
Predictability | Requires knowing nonce | Fully deterministic |
Cross-chain | Different addresses | Same address possible |
Gas Cost | Baseline | ~32,000 gas overhead |
Use Case | Standard deployments | Deterministic deployments |
Troubleshooting
Common issues and solutions:Issue | Solution |
---|---|
”Create2 deployment failed” | Ensure sufficient gas and correct bytecode format |
Address mismatch | Verify salt and bytecode are identical to computation |
Contract already deployed | CREATE2 can’t deploy to the same address twice |
Invalid bytecode | Ensure bytecode includes constructor arguments if needed |