Skip to main content

generateErc1167(implementation: Uint8Array): Uint8Array

Generates ERC-1167 minimal proxy bytecode for gas-efficient contract cloning. Creates 55-byte creation code that deploys 45-byte runtime code delegating all calls to the implementation. Parameters:
  • implementation: Uint8Array - 20-byte implementation address
Returns: Uint8Array - 55-byte creation code Throws:
  • Error - If implementation address is not 20 bytes
Example:
Defined in: src/primitives/Proxy/generateErc1167.js

Bytecode Structure

Creation Code (10 bytes)

OpcodeValueDescription
3dRETURNDATASIZEPush 0 (gas optimization)
60 2dPUSH1 45Runtime code length
80DUP1Duplicate length
60 0aPUSH1 10Creation code length
3dRETURNDATASIZEPush 0
39CODECOPYCopy runtime code to memory
81DUP2Duplicate length
f3RETURNReturn runtime code

Runtime Code (45 bytes)

OpcodeDescription
363d3d37Copy calldata to memory
3d3d3d363d73Prepare DELEGATECALL
[implementation]20-byte implementation address
5af4DELEGATECALL to implementation
3d82803eCopy returndata
903d91602b57Check success
fd5bf3REVERT or RETURN

Gas Efficiency

Deployment Cost Comparison

Clone Factory Pattern

CREATE2 Deterministic Clones

Use Cases

  • Token Factories: Deploy minimal token clones
  • NFT Collections: Gas-efficient NFT contract instances
  • Wallet Clones: Account abstraction wallet instances
  • Marketplace Listings: Per-listing contract instances
  • DAO Modules: Modular DAO component instances

See Also