A Solidity-based implementation of a Create3Factory
contract that leverages the CREATE3
opcode for deterministic address generation with integrated access control. Built using the Hardhat framework, this project facilitates secure and predictable contract deployments.
- Deterministic Address Generation: Deploy contracts to predictable addresses regardless of the deployer’s address.
- Access Control: Restricts deployment functionality to authorized entities.
- Hardhat Integration: Uses Hardhat for testing, compiling, and deployment.
Clone the repository and install the required dependencies:
git clone https://github.com/0xZothio/Create3-Factory.git
cd Create3-Factory
pnpm install
The Create3Factory
contract offers:
-
Deploy with Deterministic Address:
function create(bytes32 _salt, bytes calldata _creationCode) external onlyRole(DEPLOYER_ROLE)
Deploys a contract to a predictable address calculated from the provided
salt
. -
Get Deployed Address:
function addressOf(bytes32 _salt) external view returns (address);
Computes the deterministic address for a given
salt
. -
Access Control: Access is restricted to authorized deployers via
onlyAuthorized
modifier.
Run the following command to compile the Solidity contracts:
npx hardhat compile
To deploy the Create3Factory
contract on a local Hardhat network:
npx hardhat ignition deploy ignition/modules/deploy.ts --network localhost
Below is a sample script to deploy a contract via the Create3Factory
:
const { ethers } = require("hardhat");
async function main() {
const Create3Factory = await ethers.getContractFactory("Create3Factory");
const factory = await Create3Factory.deploy();
await factory.deployed();
console.log("Create3Factory deployed to:", factory.address);
const salt = ethers.utils.formatBytes32String("mySalt");
const bytecode = "0x6080604052348015600f57600080fd5b5060..."; // Replace with actual bytecode
const tx = await factory.create(salt, bytecode);
await tx.wait();
const deployedAddress = await factory.addressOf(salt);
console.log("Deployed contract at deterministic address:", deployedAddress);
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
Update the hardhat.config.ts
file with your desired network details:
module.exports = {
networks: {
rinkeby: {
url: "https://rinkeby.infura.io/v3/YOUR_INFURA_PROJECT_ID",
accounts: ["YOUR_PRIVATE_KEY"],
},
},
};
Replace placeholders (
YOUR_INFURA_PROJECT_ID
,YOUR_PRIVATE_KEY
) with actual values.
Deploy the Create3Factory
to a testnet or mainnet:
npx hardhat ignition deploy ignition/modules/deploy.ts --network rinkeby
This project is licensed under the MIT License. See the LICENSE
file for details.
- Utilizes the
CREATE3
opcode for deterministic and secure deployments. - Built with Hardhat.
- Inspired by modern Solidity development practices and OpenZeppelin libraries.
Feel free to fork, contribute, or suggest improvements!