Create2
Helper to make usage of the CREATE2 EVM opcode easier and safer.
CREATE2 can be used to compute in advance the address where a smart
contract will be deployed, which allows for interesting new mechanisms known
as 'counterfactual interactions'.
See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
information.
Functions
deploy
*Deploys a contract using CREATE2. The address where the contract
will be deployed can be known in advance via computeAddress.
The bytecode for a contract can be obtained from Solidity with
type(contractName).creationCode.
Requirements:
bytecodemust not be empty.saltmust have not been used forbytecodealready.- the factory must have a balance of at least
amount. - if
amountis non-zero,bytecodemust have apayableconstructor.*
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr);
computeAddress
Returns the address where a contract will be stored if deployed via deploy. Any change in the
bytecodeHash or salt will result in a new destination address.
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address);
computeAddress
Returns the address where a contract will be stored if deployed via deploy from a contract located at
deployer. If deployer is this contract's address, returns the same value as {computeAddress}.
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr);
Errors
Create2EmptyBytecode
There's no code to deploy.
error Create2EmptyBytecode();