World
Reference
Internals
Create2

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 for creationCode already.*

If the CREATE2 fails, reverts

function deploy(bytes memory creationCode, uint256 salt) internal returns (address addr);

Parameters

NameTypeDescription
creationCodebytesThe bytecode of the contract to be deployed.
saltuint256A 256-bit value that, combined with the bytecode, determines the address.

Returns

NameTypeDescription
addraddressThe 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

NameTypeDescription
byteCodebytesThe bytecode of the contract to be deployed.
saltuint256A 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

NameTypeDescription
addraddressThe address of the newly deployed contract.
saltuint256The salt value used in the CREATE2 operation.