This repo shows how to use the Transparent Proxy pattern for upgrading smart contracts. It uses most of the code from openzeppelin's repo, and adds brownie scripts on top. Freecodecamp lesson.
Please install or have installed the following:
- Install Brownie, if you haven't already. Here is a simple way to install brownie.
pip install eth-brownieOr, if that doesn't work, via pipx
pip install --user pipx
pipx ensurepath
# restart your terminal
pipx install eth-brownie- For local testing install ganache-cli Skip if you only want to use testnets
npm install -g ganache-clior
yarn add global ganache-cli- Download the mix and install dependancies.
brownie bake upgrades-mix
cd upgradesOr, you can clone from source:
git clone https://github.com/PatrickAlphaC/upgrades-mix
cd upgrades-mixIf you want to be able to deploy to testnets or work with mainnet-fork, do the following.
- Set your
WEB3_INFURA_PROJECT_ID, andPRIVATE_KEYenvironment variables.
You can get a WEB3_INFURA_PROJECT_ID by getting a free trial of Infura. At the moment, it does need to be infura with brownie. If you get lost, you can follow this guide to getting a project key. You can find your PRIVATE_KEY from your ethereum wallet like metamask.
You'll also need testnet rinkeby ETH and LINK. You can get LINK and ETH into your wallet by using the rinkeby faucets located here. If you're new to this, watch this video.
You can add your environment variables to the .env file:
export WEB3_INFURA_PROJECT_ID=<PROJECT_ID>
export PRIVATE_KEY=<PRIVATE_KEY>
AND THEN RUN source .env TO ACTIVATE THE ENV VARIABLES
(You'll need to do this everytime you open a new terminal, or learn how to set them easier).
DO NOT SEND YOUR PRIVATE KEY WITH FUNDS IN IT ONTO GITHUB
Otherwise, you can build, test, and deploy on your local environment.
brownie run scripts/01_deploy_box.py
brownie run scripts/02_upgrade_box.py
This will:
- Deploy a
Boximplementation contract - Deploy a
ProxyAdmincontract to be the admin of the proxy - Deploy a
TransparentUpgradeableProxyto be the proxy for the implementations
Then, the upgrade script will:
- Deploy a new Box implementation
BoxV2 - Upgrade the proxy to point to the new implementation contract, essentially upgrading your infrastructure.
- Then it will call a function only
BoxV2can call
brownie test