This project represents deploying of a Campaign Management Project that is upgradeable using OpenZeppelin Transparent Upgradeable Proxy: A proxy with a built in admin and upgrade interface.
In summary, first time you will deploy 3 separate contracts with the following sequence:
- Implementation: Contains contracts logic that is the the only contract that will be upgraded every time and admin contract will set this new implementation contract address in TransparentUpgradeableProxy contract.
- ProxyAdmin: Has
immutable
address that will set implementation contract address every time on TransparentUpgradeableProxy contract. - TransparentUpgradeableProxy: Has
immutable
address that will interact with user and it willdelegatecall
to implementation contract functions.
Note: Make sure you don't change storage slots order for state variables (if you intent to add new state variables, add it after original ones).
git clone --recursive https://github.com/0xhamedETH/hardhat-ethers-nextjs-campman-upgradeable.git your-directory
cd your-directory/ethereum
npm install
Compile first to create json artifacts in artifacts
folder
npx hardhat compile
You can test contracts either separately or totally.
npx hardhat test --network hardhat
npx hardhat test test/FactoryV1.test.js --network hardhat
npx hardhat test test/Campaign.test.js --network hardhat
npx hardhat test test/Token.test.js --network hardhat
npx hardhat test test/Pool.test.js --network hardhat
For this step, you first need to fill .env
file with your api keys (Alchemy
, ...)
Scripts
folder is resposible for deploying factory contract.
You can deploy in any network you want but make sure hardhat.config.js
contains that network, otherwise add it.
Note: Make sure you fill config section of deploy_Factory_v1.js
correctly.
Note: You can change buildPath
of output json file containing abi, bytecode, ... .
npx hardhat run scripts/deploy_Factory_v1.js --network rinkeby
Note: Make sure you provide your network explorer apiKey
in hardhat.config.js
.
- Implementation: You need to verify
Implementation
contract by yourself to be able to see the source code on Network Explorer (in this caseRinkeby Testnet Explorer: Etherscan
)
npx hardhat verify --network rinkeby implementationContractAddress
- TransparentUpgradeableProxy: To verify this contract as proxy, you need to follow these steps:
- Go to
Etherscan
and search theTransparentUpgradeableProxy
contract address - Go to
Contract
tab>
More Options>
Is this a proxy?>
Verify
- ProxyAdmin: This contract is already verified.
For upgrade, make sure you fill proxyAddress
in config
section of upgrade_Factory_v2
script.
npx hardhat run scripts/upgrade_Factory_v2.js --network rinkeby
After this, 2 transactions will send:
1st to deploy new Implementation
contract
2nd to call upgrade
function of ProxyAdmin
contract.