Create2Deployer

0x2cfbafad4ae4f3f2ba12047a80fa0b1d90978c57

Verification
Unverified
v0.8.26+commit.8a97fa7a
Type
Contract
935 bytes
ABI entries
4
2 read · 1 write
License
none

Contract information

Address
0x2cfbafad4ae4f3f2ba12047a80fa0b1d90978c57
Chain
Robinhood Chain (4663)
Compiler
v0.8.26+commit.8a97fa7a
Optimization
Enabled
Creation tx
0xf2aa323360…10cafdc762

Token

Not a token

This contract does not expose ERC-20 metadata.

Read contract (2)

computeAddress(bytes32, bytes32)address
computeAddressWithDeployer(bytes32, bytes32, address)address

Events (1)

Deployed

ABI

[
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": false,
        "internalType": "address",
        "name": "addr",
        "type": "address"
      }
    ],
    "name": "Deployed",
    "type": "event"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "bytes32",
        "name": "bytecodeHash",
        "type": "bytes32"
      }
    ],
    "name": "computeAddress",
    "outputs": [
      {
        "internalType": "address",
        "name": "predictedAddress",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "bytes32",
        "name": "bytecodeHash",
        "type": "bytes32"
      },
      {
        "internalType": "address",
        "name": "deployer",
        "type": "address"
      }
    ],
    "name": "computeAddressWithDeployer",
    "outputs": [
      {
        "internalType": "address",
        "name": "predictedAddress",
        "type": "address"
      }
    ],
    "stateMutability": "pure",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "bytes32",
        "name": "salt",
        "type": "bytes32"
      },
      {
        "internalType": "bytes",
        "name": "bytecode",
        "type": "bytes"
      }
    ],
    "name": "deploy",
    "outputs": [
      {
        "internalType": "address",
        "name": "addr",
        "type": "address"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Source code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Create2Deployer {
    event Deployed(address addr);

    /**
     * @dev Deploys a contract using CREATE2.
     * @param salt The salt to use for deployment.
     * @param bytecode The bytecode of the contract to deploy.
     * @return addr The address of the deployed contract.
     */
    function deploy(bytes32 salt, bytes memory bytecode) external returns (address addr) {
        require(bytecode.length != 0, "Bytecode is empty");

        // Perform the CREATE2 deployment
        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
        }

        require(addr != address(0), "Failed to deploy contract");

        emit Deployed(addr);
    }

    /**
     * @dev Computes the address of a contract deployed using CREATE2.
     * @param salt The salt to use for deployment.
     * @param bytecodeHash The keccak256 hash of the contract bytecode.
     * @return predictedAddress The address of the deployed contract.
     */
    function computeAddress(bytes32 salt, bytes32 bytecodeHash) external view returns (address predictedAddress) {
        predictedAddress = address(uint160(uint(keccak256(abi.encodePacked(
            bytes1(0xff),
            address(this),
            salt,
            bytecodeHash
        )))));
    }

    /**
     * @dev Computes the address of a contract deployed using CREATE2 (with deployer specified).
     * @param salt The salt to use for deployment.
     * @param bytecodeHash The keccak256 hash of the contract bytecode.
     * @param deployer The address of the deployer.
     * @return predictedAddress The address of the deployed contract.
     */
    function computeAddressWithDeployer(
        bytes32 salt,
        bytes32 bytecodeHash,
        address deployer
    ) external pure returns (address predictedAddress) {
        predictedAddress = address(uint160(uint(keccak256(abi.encodePacked(
            bytes1(0xff),
            deployer,
            salt,
            bytecodeHash
        )))));
    }
}
Chain explorer2797msChain node76ms