Skip to content

Create2Deployer

0x4e59b44847b379578588920cA78FbF26c0B4956C

Can be used to deploy contracts with CREATE2 Factory.

State Variables

CREATE2_FACTORY

_Used by default when deploying with create2, https://github.com/Arachnid/deterministic-deployment-proxy._

solidity
address public constant _CREATE2_FACTORY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;

Functions

deployWithCreate2

Deploys a contract using the _CREATE2_FACTORY.

The call data is encoded as abi.encodePacked(salt, initCode).

The return data is abi.encodePacked(addr).

solidity
function deployWithCreate2(uint256 salt, bytes memory initCode) internal returns (address addr);

Parameters

NameTypeDescription
saltuint256The salt to use for the deployment.
initCodebytesThe init code of the contract to deploy.

Returns

NameTypeDescription
addraddressThe address of the deployed contract.

deployWithCreate2IfNecessary

Deploys a contract using the _CREATE2_FACTORY if it hasn't been deployed yet.

solidity
function deployWithCreate2IfNecessary(uint256 salt, bytes memory initCode) internal returns (address addr);

getCreate2Address

Returns the deterministic address of a contract for the given salt and init code.

Assumes that the contract will be deployed using deployWithCreate2.

solidity
function getCreate2Address(uint256 salt, bytes memory initCode) internal pure returns (address);

Parameters

NameTypeDescription
saltuint256The salt to use for the deployment.
initCodebytesThe init code of the contract to deploy.

Returns

NameTypeDescription
<none>addressaddr The address of the deployed contract.

getCreate2Address

Returns the deterministic address of a contract for the given salt and init code.

Assumes that the contract will be deployed using deployWithCreate2.

solidity
function getCreate2Address(uint256 salt, bytes32 initCodeHash) internal pure returns (address);

Parameters

NameTypeDescription
saltuint256The salt to use for the deployment.
initCodeHashbytes32The init codehash of the contract to deploy.

Returns

NameTypeDescription
<none>addressaddr The address of the deployed contract.

deployProxyWithCreate2

Deploys a ERC1967 Proxy for the already deployed implementation contract.

solidity
function deployProxyWithCreate2(address implementation, uint256 salt) internal returns (address);

Parameters

NameTypeDescription
implementationaddressThe implementation contract address.
saltuint256The salt that will be used for the deployment of the proxy.

Returns

NameTypeDescription
<none>addressinstance The determinitic address of the deployed proxy contract.

deployProxyWithCreate2IfNecessary

Deploys a ERC1967 Proxy for the already deployed implementation contract if it hasn't been deployed yet.

solidity
function deployProxyWithCreate2IfNecessary(address implementation, uint256 salt) internal returns (address);

getCreate2ProxyAddress

Returns the deterministic address of a ERC1967 proxy for the given implementation and salt.

Assumes that the proxy is deployed using deployProxyWithCreate2.

solidity
function getCreate2ProxyAddress(address implementation, uint256 salt) internal pure returns (address);

Parameters

NameTypeDescription
implementationaddressThe implementation contract address.
saltuint256The salt that will be used for the deployment of the proxy.

Returns

NameTypeDescription
<none>addressinstance The address of the deployed proxy contract.