This project demonstrates how to build and upgrade Ethereum smart contracts using the Transparent Proxy pattern with Hardhat and OpenZeppelin Contracts (v5).
It serves as a practical reference for understanding:
- Proxy-based upgradeability
- Implementation versioning
- Safe contract upgrades without losing on-chain state
- Transparent Proxy pattern
- ProxyAdmin (OpenZeppelin v5)
- Implementation upgrades (V1 → V2 → V3)
- Storage layout compatibility
- Hardhat deployment & upgrade scripts
git clone https://github.com/ndubuisi-ugwuja/smartcontracts-upgrades.git
cd smartcontracts-upgradesyarn installyarn hardhat compileyarn hardhat ignition deploy ignition/modules/UpgradeableContractModule.js --network sepolia --verifyyarn hardhat run scripts/getProxyAdmin.js --network sepoliaCreate a .env file:
SEPOLIA_RPC_URL=your_sepolia_rpc__url
PRIVATE_KEY=your_private_key
ETHERSCAN_API_KEY=api_key
COINMARKETCAP_API_KEY=api_key
PROXYADDRESS=your_proxy_address // Address from step 4
PROXYADMINADDRESS=your_proxyadmin_address // Address from step 5
EIP1967ADMINSLOT=0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103
EIP1967IMPLEMENTATIONSLOT=0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc // For staging test// Upgrade to version 2
yarn hardhat run scripts/upgradeToV2.js --network sepolia
// Upgrade to version 3
yarn hardhat run scripts/upgradeToV3.js --network sepoliaEach upgrade deploys a new implementation and updates the proxy via ProxyAdmin, while preserving contract state.
// Unit test
yarn hardhat test --network hardhat
// Staging test
yarn hardhat test --network sepolia- Storage layout must remain compatible between versions
- Never change the order or type of existing state variables
- Always test upgrades on testnets before mainnet
This project is unlicensed. You are free to use, modify, and integrate it into your own projects.
Ndubuisi Ugwuja