Contract Source Code:
File 1 of 1 : Create2Factory.sol
// SPDX-License-Identifier: MIT pragma solidity ^0.8.19; contract Create2Factory { // Contract owner address public immutable owner; // Event emitted when a new contract is deployed event ContractDeployed(address indexed deployedAddress, uint256 indexed salt); constructor() { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner, "Not authorized"); _; } /** * @dev Deploys a contract using CREATE2 * @param bytecode The contract bytecode to deploy * @param salt Unique value for deterministic address generation * @return deployedAddress The address where the contract was deployed */ function deploy(bytes memory bytecode, uint256 salt) external onlyOwner returns (address deployedAddress) { // Compute the address where contract will be deployed bytes32 hash = keccak256( abi.encodePacked( bytes1(0xff), address(this), salt, keccak256(bytecode) ) ); deployedAddress = address(uint160(uint256(hash))); // Check if address is already in use require(deployedAddress.code.length == 0, "Address already in use"); // Deploy the contract assembly { deployedAddress := create2(0, add(bytecode, 0x20), mload(bytecode), salt) } // Verify deployment was successful require(deployedAddress != address(0), "Deployment failed"); emit ContractDeployed(deployedAddress, salt); } /** * @dev Computes the address where a contract will be deployed using CREATE2 * @param bytecode The contract bytecode * @param salt The salt value * @return The address where the contract would be deployed */ function computeAddress(bytes memory bytecode, uint256 salt) public view returns (address) { return address(uint160(uint256(keccak256(abi.encodePacked( bytes1(0xff), address(this), salt, keccak256(bytecode) ))))); } }
Please enter a contract address above to load the contract details and source code.
Please DO NOT store any passwords or private keys here. A private note (up to 100 characters) can be saved and is useful for transaction tracking.
This website uses cookies to improve your experience. By continuing to use this website, you agree to its Terms and Privacy Policy.