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
immutableaddress that will set implementation contract address every time on TransparentUpgradeableProxy contract. - TransparentUpgradeableProxy: Has
immutableaddress that will interact with user and it willdelegatecallto 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-directorycd your-directory/ethereum
npm installCompile first to create json artifacts in artifacts folder
npx hardhat compileYou 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 hardhatFor 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 rinkebyNote: Make sure you provide your network explorer apiKey in hardhat.config.js.
- Implementation: You need to verify
Implementationcontract 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
Etherscanand search theTransparentUpgradeableProxycontract address - Go to
Contracttab>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 rinkebyAfter this, 2 transactions will send:
1st to deploy new Implementation contract
2nd to call upgrade function of ProxyAdmin contract.