Create2Factory

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "SRC/Create2Factory.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

/// @title Create2Factory
/// @notice Deterministic contract deployment using CREATE2
/// @dev This factory allows prediction of contract addresses before deployment
contract Create2Factory {
    /// @notice Emitted when a contract is deployed
    /// @param deployed The address of the deployed contract
    /// @param salt The salt used for deployment
    event ContractDeployed(address indexed deployed, bytes32 indexed salt);

    /// @notice Deploy a contract using CREATE2
    /// @param salt The salt for deterministic address generation
    /// @param initCode The contract creation bytecode (creationCode + constructorArgs)
    /// @return addr The address of the deployed contract
    function deploy(bytes32 salt, bytes memory initCode) external payable returns (address addr) {
        assembly {
            // create2(value, offset, size, salt)
            addr := create2(callvalue(), add(initCode, 0x20), mload(initCode), salt)

            // Revert if deployment failed (address has no code)
            if iszero(extcodesize(addr)) {
                revert(0, 0)
            }
        }

        emit ContractDeployed(addr, salt);
    }

    /// @notice Compute the address of a contract deployed with CREATE2
    /// @param salt The salt for deterministic address generation
    /// @param initCodeHash The keccak256 hash of the init code
    /// @return The predicted address where the contract will be deployed
    function computeAddress(bytes32 salt, bytes32 initCodeHash) external view returns (address) {
        return address(uint160(uint256(
            keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, initCodeHash))
        )));
    }

    /// @notice Helper to get the init code hash for a contract
    /// @param initCode The contract creation bytecode
    /// @return The keccak256 hash of the init code
    function getInitCodeHash(bytes memory initCode) external pure returns (bytes32) {
        return keccak256(initCode);
    }
}
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "viaIR": true,
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Factory|addr:0x4acac2da5442205ec25169b6d38f9a4d4475d57b|verified:true|block:23627233|tx:0x0db1677942b2db737414bc5b3858738f43f825742510813fa3dca112436ed1ab|first_check:1761069043

Submitted on: 2025-10-21 19:50:45

Comments

Log in to comment.

No comments yet.