Updated example of OpenZeppelin Create2
library using Solidity 0.8.24 and OZ v 5.0.2 using the Hardhat framework.
This demo shows how to use Create2 to deploy a vanilla Vault contract with Create2.deploy and the new keyword as well as an upgradeable Vault via an Upgradeable Beacon.
Check out CreateX while you are researching this topic.
IMPORTANT: If you change anything within a smart contract (even white spaces), you will get a different deployment address across networks.
git clone https://github.com/TtheBC01/create2-example.git
cd create2-example
npm installcp .env-sample .envThen add add either a private key or mnemonic with testnet funds if you want to deploy to a testnet.
This example has already been deployed to Fuji and Sepolia testnets, so you'll need to change the salt value or the owner address to something else if you want to try that yourself.
npx hardhat testChange the owner address in the VaultFactory.ts module to an account you control before deploying:
npx hardhat ignition deploy ignition/modules/VaultFactory.ts --network sepolia --strategy create2VaultFactory address on fuji and sepolia: 0x0568846C86B727Ba76794fF1bFD0713384d879ab
# predict the address of a proxy Vault
npx hardhat getProxyAddress --name TtheBC01 --network fuji
# predict the address of a regular Vault
npx hardhat getVaultAddress --name TtheBC01 --network fuji
# deploy a proxy Vault (change the owner and name to something else)
npx hardhat deployProxy --name TtheBC01 --owner 0x9fEad8B19C044C2f404dac38B925Ea16ADaa2954 --network fuji
# deploy a regular Vault (change the owner and name to something else)
npx hardhat deployVault --name TtheBC01 --owner 0x9fEad8B19C044C2f404dac38B925Ea16ADaa2954 --network fuji
# check the owner address of a proxy Vault
npx hardhat getProxyOwner --name TtheBC01 --network sepolia
# check the owner address of a regular Vault
npx hardhat getVaultOwner --name TtheBC01 --network sepolia