One of the basic rules of EVM is that once a contract is deployed, it cannot be changed. Instead, an upgradable smart contract uses a special proxy pattern. The latter involves deploying proxy contracts and implementation contracts (logic contracts).
- User interacts with proxy contract that intiates fallback function that deligates call to contract implementation(V1).
- Proxy contract has upgrade function to deligate call to new contract implementation(V2).
- For security purpose, upgrade function should be invoked by only Admin.
- Admin interacts with proxy admin contract which interm calls upgrade function of the proxy
Note:
- upgradable contract implementation have no constructor.
npx hardhat compile
# 3 transactions (deploy V1, ProxyAdmin and proxy)
env $(cat .env) npx hardhat run --network ropsten scripts/deploy_box_v1.js
# 2 transactions (deploy V2, ProxyAdmin.upgrade)
env $(cat .env) npx hardhat run --network ropsten scripts/upgrade_box_v2.js
IMP=0x892f0dF05f993A7050F0e2DFC865b170776d3759
IMP=0xd0e76D0ea91f25Ce0Ad3e48e3CeD94d98806Fe6d
env $(cat .env) npx hardhat verify --network ropsten $IMP