Create2
Git Source (opens in a new tab)
Library to deploy contracts using the CREATE2 opcode.
Functions
deploy
*Deploys a contract using CREATE2
. The address where the contract
will be deployed can be known in advance.
The bytecode for a contract can be obtained from Solidity with
type(contractName).creationCode
.
Requirements:
creationCode
must not be empty.salt
must have not been used forcreationCode
already.*
If the CREATE2 fails, reverts
function deploy(bytes memory creationCode, uint256 salt) internal returns (address addr);
Parameters
Name | Type | Description |
---|---|---|
creationCode | bytes | The bytecode of the contract to be deployed. |
salt | uint256 | A 256-bit value that, combined with the bytecode, determines the address. |
Returns
Name | Type | Description |
---|---|---|
addr | address | The address of the newly deployed contract. |
Create2Factory
Git Source (opens in a new tab)
Helper Contract to facilitate create2 deployment of Contracts.
Functions
deployContract
Deploys a new Contract using create2.
Emit ContractDeployed on success
function deployContract(bytes memory byteCode, uint256 salt) public;
Parameters
Name | Type | Description |
---|---|---|
byteCode | bytes | The bytecode of the contract to be deployed. |
salt | uint256 | A 256-bit value that, combined with the bytecode, determines the address. |
Events
ContractDeployed
Emitted when a new contract is deployed using the deployContract
function.
event ContractDeployed(address addr, uint256 salt);
Parameters
Name | Type | Description |
---|---|---|
addr | address | The address of the newly deployed contract. |
salt | uint256 | The salt value used in the CREATE2 operation. |