S Price: $0.51632 (+1.79%)

Contract Diff Checker

Contract Name:
BeefyContractDeployer

Contract Source Code:

File 1 of 1 : BeefyContractDeployer

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

contract BeefyContractDeployer {

    event ContractDeployed(bytes32 indexed salt, address deploymentAddress);

    // Deploy a contract, if this address matches contract deployer on other chains it should match deployment address if salt/bytecode match., 
    function deploy(bytes32 _salt, bytes memory _bytecode) external returns (address deploymentAddress) {
        address addr;
        assembly {
            addr := create2(0, add(_bytecode, 0x20), mload(_bytecode), _salt)
            if iszero(extcodesize(addr)) {
                 revert(0, 0)
            }
        }

        emit ContractDeployed(_salt, addr);
        return addr;
    }

    // Get address by salt and bytecode.
    function getAddress(bytes32 _salt, bytes memory _bytecode) external view returns (address) {
        bytes32 hash = keccak256(
            abi.encodePacked(
                bytes1(0xff), address(this), _salt, keccak256(_bytecode)
            )
        );
        return address (uint160(uint(hash)));
    }

    // Creat salt by int or string.
    function createSalt(uint _num, string calldata _string) external pure returns (bytes32) {
        return _num > 0 ? keccak256(abi.encode(_num)) : keccak256(abi.encode(_string));
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):