DEV Community

Cover image for Ethereum-Solidity Quiz Q31: What is the difference between CREATE and CREATE2 transaction types?
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q31: What is the difference between CREATE and CREATE2 transaction types?

CREATE (Regular Deployment)

// Address = keccak256(deployer, nonce)
new CreateContract(owner);
Enter fullscreen mode Exit fullscreen mode
──────────────────────────────────────────────────────────────────
                             CREATE                                         
──────────────────────────────────────────────────────────────────

Example:
  Deployer: 0x4f98e7507c578e2341B5b874E9a7C910aA8Db3e1
  Nonce: 234
  ──────────────────────────────────────────────────────
  Result: 0xa729B8363b472E8A3f20eF4E6210Cdd70C0cF5aB

Characteristics:
  ✅ Simple, default behavior
  ❌ Address changes if nonce changes
  ❌ Can't predict address before deployment
  ❌ Different address on each chain (different nonces)
Enter fullscreen mode Exit fullscreen mode

CREATE2 (Deterministic Deployment)

// Address = keccak256(0xff, factory, salt, initCodeHash)
// Used automatically by Foundry for libraries
Enter fullscreen mode Exit fullscreen mode
─────────────────────────────────────────────────────────────────
                              CREATE2                                         
─────────────────────────────────────────────────────────────────

Example:
  Factory: 0x4f98e7507c578e2341B5b874E9a7C910aA8Db3e1 (Deterministic Deployer)
  Salt: 0x0000...0000
  InitCode: <bytecode of Library>
  ──────────────────────────────────────────────────────
  Result: 0xEdA41181EAB196E739140876C5fF35e2DFde188a

Characteristics:
  ✅ Same address on ALL chains (if same salt + bytecode)
  ✅ Predictable before deployment
  ✅ Great for libraries, factories, cross-chain deploys
  ❌ Slightly more complex
  ❌ Requires a factory contract
Enter fullscreen mode Exit fullscreen mode

Visual Comparison

CREATE:
─────────────────────────────────────────────────────────────────

Deployer (0x4f98...) ──► Deploy Contract
         │
         │  address = hash(deployer, nonce)
         │
         ▼
    Ethereum: 0xAAA...  (nonce = 100)
    Base:     0xBBB...  (nonce = 50)   ◄── Different addresses!
    Polygon:  0xCCC...  (nonce = 75)


CREATE2:
─────────────────────────────────────────────────────────────────

Deployer ──► Factory (0x4e59b448...) ──► Deploy Contract
                    │
                    │  address = hash(0xff, factory, salt, bytecodeHash)
                    │
                    ▼
    Ethereum: 0xEdA411...
    Base:     0xEdA411...  ◄── SAME address everywhere!
    Polygon:  0xEdA411...
Enter fullscreen mode Exit fullscreen mode

Top comments (0)