1/5
_Follow along the course with this video._ --- ### UUPS Deploy At this point we're buried in context and it's time to see this in action. Here's how we're going to accomplish this, we're going to: 1. Deploy BoxV1 2. Get an address 3. Deploy Proxy with BoxV1 address 4. Verify that everything works 5. Deploy BoxV2 6. Point Proxy to BoxV2 We'll begin by creating two scripts, `script/DeployBox.s.sol` and `script/UpgradeBox.s.sol` Our deployment script should be very familiar to us by now! > ❗ **PROTIP** > Repetition is the mother of skill. ```js //SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import {Script} from "forge-std/Script.sol"; import {BoxV1} from "../src/BoxV1.sol"; contract DeployBox is Script { function run() external returns(address) { address proxy = deployBox(); return proxy; } function deployBox() public returns(address) { vm.startBroadcast(); BoxV1 box = new BoxV1(); // Implementation vm.stopBroadcast(); } } ``` At this point we'll want to import and deploy our proxy. The proxy we're going to use is ERC1967. Feel free to read more about its specifics in the [**OpenZeppelin Documentation**](https://docs.openzeppelin.com/contracts/4.x/api/proxy) or [**Ethereum Improvement Proposals**](https://eips.ethereum.org/EIPS/eip-1967). In order to access OpenZeppelin's ERC1967 implementation, we'll need to install our standard OpenZeppelin/Contracts library and import it into our deploy script. ```bash forge install OpenZeppelin/openzeppelin-contracts --no-commit ``` ```js import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; ``` We'll also need to add this remapping to our `foundry.toml`. ```js remappings = [ "@openzeppelin/contracts=lib/openzeppelin-contracts/contracts", "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts", ]; ``` Finally, we can add the deployment of our proxy to our deploy script. The ERC1967Proxy contract _does_ have a constructor we need to consider. ```js constructor(address implementation, bytes memory _data) payable { ERC1967Utils.upgradeToAndCall(implementation, _data); } ``` This constructor is expecting two arguments to be passed, the first is our implementation contract, as to be expected. The second is `_data`. This data parameter can be used to pass function call data to be executed after deployment ie - calling an initializer function. We won't be employing this functionality, so our data parameter is going to be empty. ```js //SPDX-License-Identifier: MIT pragma solidity ^0.8.18; import {Script} from "forge-std/Script.sol"; import {BoxV1} from "../src/BoxV1.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; contract DeployBox is Script { function run() external returns(address) { address proxy = deployBox(); return proxy; } function deployBox() public returns(address) { vm.startBroadcast(); BoxV1 box = new BoxV1(); // Implementation ERC1967Proxy proxy = new ERC1967Proxy(address(box), ""); vm.stopBroadcast(); return address(proxy); } } ``` ### Wrap Up Things are looking great! At this point we should be able to run `forge build` to ensure things are compiling as expected. In the next lesson we'll configure our script to upgrade our BoxV1 protocol to BoxV2. See you there!
Guide on deploying upgradeable smart contracts, focusing on the deployment process and best practices.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
Solidity Developer
Advanced FoundryDuration: 36min
Duration: 3h 06min
Duration: 5h 02min
Duration: 2h 47min
Duration: 1h 23min
Duration: 4h 28min
Duration: 1h 19min
Duration: 58min
Course Overview
About the course
Advanced smart contract development
How to develop a stablecoin
How to develop a DeFi protocol
How to develop a DAO
Advanced smart contracts testing
Fuzz testing
Manual verification
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Guest lecturers:
Juliette Chevalier
Lead Developer relations at Aragon
Nader Dabit
Director of developer relations at Avara
Ally Haire
Developer relations at Protocol Labs
Harrison
Founder at GasliteGG
Last updated on November 29, 2024
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar