Open Zeppelin Upgradeable Contracts

  Рет қаралды 37,570

Smart Contract Programmer

Smart Contract Programmer

Күн бұрын

Пікірлер: 80
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
0:00 - Overview 1:44 - Project setup 4:28 - Deploy Box V1 script 7:10 - Execute deploy script 8:29 - Verify Box V1 on Etherscan 9:48 - Setup proxy / implementation on Etherscan 10:47 - Upgrade Box V2 script 11:49 - Execute upgrade script 13:21 - Upgrade demo - call inc()
@0x_minato4thh
@0x_minato4thh 2 жыл бұрын
u are the reason why I get internships........Happy Teachers Day.........love from India
@Open4Profit
@Open4Profit 3 жыл бұрын
Excellent - Learning smart contracts in depth now. Thanks for these awesome contents.
@0ManishSharma0
@0ManishSharma0 3 жыл бұрын
You have been my guardian angel in my process of learning solidity. Huge thanks to you for sharing the quality content for free
@enadiz246
@enadiz246 3 жыл бұрын
learnt that you can verify from CLI and how to enable reading as proxy on etherscan. Very useful!
@omadalosso
@omadalosso 2 жыл бұрын
Thanks for the video, the diagram made the whole pattern really easy to understand
@salem232
@salem232 3 жыл бұрын
Very helpful and super clear example 🤩 thank you so much!!
@tailyfale
@tailyfale Жыл бұрын
1:38 - "this is done for a security reason which I will not discuss in this video" - I still don't get what security reason is here and which of your links should I check to know moree, could you please tell? Tbh I don't even understand WHAT is done for "a security reason". A smart contract acting as an Admin instead of an ordinary account? Or something else?
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
Functions selectors can be crafted to call upgrade instead of another function. forum.openzeppelin.com/t/beware-of-the-proxy-learn-how-to-exploit-function-clashing/1070 This is prevented by forwading function call either to the implementation or execute some code inside the proxy depending on msg.sender. If msg.sender is the admin, then it will execute the code inside the proxy contract. Otherwise it will execute the code inside the implementation via delegatecall. Having admin be an EOA is not ideal, since the EOA may need to call functions inside the implementation. Hence the admin is set to a AdminProxy contract.
@tailyfale
@tailyfale Жыл бұрын
@@smartcontractprogrammer thank you!
@zachz6620
@zachz6620 2 жыл бұрын
One thing that is very confusing..... I thought that users are supposed to interact with the proxy contract? So shouldn't the proxy have all the functions the Box and Boxv2 contracts have? Users should be calling functions on the proxy contract which are getting routed to the implementation contract (box) via delegate call right? That date is then returned to the Proxy and the storage in proxy is used. It doesn't appear we set this up in a way that allows users to interact with the Proxy as it does not have the function to return the value.
@shaharnechmad2586
@shaharnechmad2586 2 жыл бұрын
Great video. Thx for creating it! Would love to see one also with OpenZeplin UUPS
@sweetjimmy
@sweetjimmy 2 жыл бұрын
12:23 on running this command I'm getting this error TypeError: Cannot read properties of undefined (reading 'encodeDeploy') at getDeployData (....node_modules\@openzeppelin\hardhat-upgrades\src\utils\deploy-impl.ts:49:45) PLEASE HELP! Here's my script: const { ethers, upgrades } = require("hardhat"); const PROXY = "0xc25e45081aEB6075cc041b5346C351c820fD3306"; async function main() { const BoxV2 = ethers.getContractFactory("BoxV2"); await upgrades.upgradeProxy(PROXY, BoxV2); console.log("Box upgraded!"); } main().catch((error) => { console.error(error); process.exitCode = 1; });
@ThePersepolis32
@ThePersepolis32 3 жыл бұрын
Thank you very much for creating these contents.
@andrewt5348
@andrewt5348 3 жыл бұрын
Thank you very much for doing this, it has been very helpful!
@fabiano.nascimento
@fabiano.nascimento 2 жыл бұрын
Excellent! OpenZeppelin docs recommend shifting towards UUPS proxies. The same docs say that to use both UUPS and Transparent we call deployProxy and upgradeProxy functions. However, I haven't found how to distinguish when I want to follow UUPS pattern. Would you mind to make a video showing us how to follow the UUPS Proxy pattern?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
I haven't used UUPS yet
@lianglaw6923
@lianglaw6923 3 жыл бұрын
Brother, thanks for your sharing. Maybe you could share with us a little bit on reasons behind why we need to upgrade existing smart contract? Reason I am asking. 1) Purpose of smart contract is do not change the logic once the code was uploaded to the blockchain. 2) Even if we really need to upgrade. We can directly upload a new smart contract and point the front end to the latest contract.(Like uniswap and pancakeswap). Right? I got no clue why we need to upgrade existing smart contract.
@vitor4944
@vitor4944 3 жыл бұрын
i have the same doubt 🥶
@0ManishSharma0
@0ManishSharma0 3 жыл бұрын
The reason we need upgradeable contracts are: - Deploying new contracts would not allow us to have history of old states ( eg, the token amount for addresses will be lost if we deploy a fresh new updated instance ) - In case of exploit discovery by white hats, we need patches/fixes too.
@lianglaw6923
@lianglaw6923 3 жыл бұрын
​@@0ManishSharma0 But if we could easily modify a smart contract, the main purpose of a smart contract(unchangeble) is gone right? I think that is the reason why protocol like uniswap and pancakeswap come with v1 and v2 rather than v1.1xx.
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
I am just showing you how to do it. Whether you need it or not is another question
@prolingua
@prolingua 2 жыл бұрын
In the upgrade script, you specify the address of the PROXY but what is actually executed first is function upgrade() of the PROXY ADMIN, right? If so, how does the script know the address of PROXY ADMIN?
@ThanhNguyen-ru6re
@ThanhNguyen-ru6re 2 жыл бұрын
Great video. Thanks for your sharing!!!!!
@andreujuanc
@andreujuanc 3 жыл бұрын
Great content!! Keep it up.
@saulgood2548
@saulgood2548 3 жыл бұрын
Everything would be the same if you substitute Hardhat for Truffle?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
Not sure if Truffle has OZ upgradeable plugin
@Antonym-b5o
@Antonym-b5o 2 жыл бұрын
Ohh if i change the contract version i lost my data in contract storage? can you explain please?
@seamini9172
@seamini9172 3 жыл бұрын
Could proxy contracts be used to offload transaction gas costs from the implementation contract? For chains that have gas limits for transactions could proxies be used to take the costly gas function calls and encapsulate them in another contract that the proxy calls?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
A proxy increases gas cost
@sulimanmukhtar4269
@sulimanmukhtar4269 3 жыл бұрын
Waiting for the next video 🥺
@countsofmath9623
@countsofmath9623 2 жыл бұрын
Thank you! If we want to initialize a new variable (as in create a new variable and assign it a default value) in our second version, how would we do that without the initialize function?
@mikeha
@mikeha 2 жыл бұрын
I don't think you can add a variable as it uses the storage of the proxy contract, not the implementation contract. And since the proxy is also immutable, we cannot make any changes to it
@aaronneuville701
@aaronneuville701 2 жыл бұрын
Hello, i got a question regarding the Ownabable Delegate Proxy contract… I cannot find my answer anywhere and opensea refers me to their discord (where i get no answer) So I accidentally sent eth funds to the “OwnableDelegateProxy”-contract of which i’m the owner. I just wonder if it is possible to get these funds back? And if so how it is done, or if anybody knows resources i should check out to solve it? Thank you in advance
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
You can if the contract has a function to withdraw the ETH
@pythusiast4701
@pythusiast4701 Жыл бұрын
You are just awesome!!!!!!!!
@seamini9172
@seamini9172 3 жыл бұрын
Does BoxV2 inherit all functionality from BoxV1 or do you need to recreate those functions in the BoxV2 contract completely?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
Why would it inherit code from BoxV1?
@mgeeta1365
@mgeeta1365 2 жыл бұрын
I have only one contract creation that's the proxy contract , why can't I see the other two contracts.
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
use etherscan - you will see 3 consecutive transactions
@mgeeta1365
@mgeeta1365 2 жыл бұрын
@@smartcontractprogrammer I mean I checked the etherscan and found only one. And I was trying to redeploy , is that the reason?
@jeffcui3660
@jeffcui3660 2 жыл бұрын
Amazing video. If we want to change the storage variable, we have to redeploy the contract, am I right? Thanks!
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Never change old storage layout. However it's safe to append new state variables
@سرالحضارات-ي4ق
@سرالحضارات-ي4ق 2 жыл бұрын
Can you explain to me how you can let me make profits more than gas Fees for flash loans or flash minting
@alejandrocampo23
@alejandrocampo23 2 жыл бұрын
Amazing video but im having trouble upgrading to V2. Once I set the PROXY constant of the verified proxy contract and run the upgrade script I am getting "Contract 0x... doesn't look like an administered ERC 1967 proxy" evethough everything looks fine on polygonscan... Help plz!
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
I've deployed on ETH testnet. Maybe polygon is a little different
@twogroup825
@twogroup825 2 жыл бұрын
Your videos are amazing! Can you explain pullPayments?
@战忽局保洁阿姨
@战忽局保洁阿姨 2 жыл бұрын
good job !
@varundoshi5136
@varundoshi5136 Жыл бұрын
Please make a similar tutorial for Proxy using Foundry
@ethansayagh2969
@ethansayagh2969 2 жыл бұрын
Aweome and well explained.
@crocodilearms2093
@crocodilearms2093 2 жыл бұрын
How do you do this in remix?
@mgeeta1365
@mgeeta1365 2 жыл бұрын
Can't we write upgradeable contracts using Remix IDE?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Yes, but for production use Open Zeppelin
@jaikumar5838
@jaikumar5838 Жыл бұрын
What happened when you have funds in the v1 ?
@smartcontractprogrammer
@smartcontractprogrammer Жыл бұрын
funds will still be in v2
@asthayadav4931
@asthayadav4931 2 жыл бұрын
Does this come under diamond proxy or UUPS?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
neither
@MatiasSidler
@MatiasSidler 2 жыл бұрын
Hey bro! Amazing video. One question: I'm using a local network (not with ganache) and I don't have a block explorer. Is there any other way to get the proxy and proxy admin addresses?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Look for contract creations from your account. There should be 3 (ProxyAdmin, Proxy, Implementation)
@crypto_peng
@crypto_peng 2 жыл бұрын
AWESOME
@muhammadabdulrehman3744
@muhammadabdulrehman3744 2 жыл бұрын
env $(cat .env) what does this please in the npx command?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Linux command to load environment variables inside .env file
@guillermin1979
@guillermin1979 2 жыл бұрын
github link doesn't work
@blockchainapp4472
@blockchainapp4472 3 жыл бұрын
where did we use the admin proxy in here?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
upgrade can only be called by ProxyAdmin
@blockchainapp4472
@blockchainapp4472 3 жыл бұрын
@@smartcontractprogrammer yes but the only thing that differentiates the first and second deployment is the proxy address that we provide. Where is anything specific to proxy admin is being written? while deployment. Or am I missing something related to the env keys?
@jaystance9856
@jaystance9856 2 жыл бұрын
Please I’m stuck , what do I use as my PRI_API? What does that even mean??? Also in case of next time you are shooting a video that assume that we all know what’s going on, try to explain every line of code it’s necessary I’m still your biggest fan ✌️, watching through all your playlists
@jaystance9856
@jaystance9856 2 жыл бұрын
Please what do I use for the PRI API???
@alexchang8180
@alexchang8180 2 жыл бұрын
your wallet private key in Ropsten.. make sure u have some test ethers in it in order for it to work..
@JonJoshChua
@JonJoshChua 2 жыл бұрын
Could you do one using a UUPS proxy?
@smartcontractprogrammer
@smartcontractprogrammer 2 жыл бұрын
Sure once I get an opportunity to use it
@pulsechainalltheway1845
@pulsechainalltheway1845 8 ай бұрын
Great video
@crypto_peng
@crypto_peng 3 жыл бұрын
nice nicenice
@bitcoinshitcoin5116
@bitcoinshitcoin5116 3 жыл бұрын
Please erc20 waiting
@cryptosurfer2369
@cryptosurfer2369 3 жыл бұрын
Hi mate are you for hire? i can email you?
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
No I am not looking for a job
@benjaminho351
@benjaminho351 3 жыл бұрын
Diamond Standard pls
@smartcontractprogrammer
@smartcontractprogrammer 3 жыл бұрын
Over engineered. Stay away :D
@benjaminho351
@benjaminho351 3 жыл бұрын
@@smartcontractprogrammer might be the only way for contracts that exceed the 24KB size limit tho
@JenniferBrown-n3r
@JenniferBrown-n3r 3 ай бұрын
Walker Timothy Thompson Brian Lewis Ruth
Access Control | Solidity 0.8
11:40
Smart Contract Programmer
Рет қаралды 15 М.
Open Zeppelin Upgradeable Contracts - Unsafe Code
14:43
Smart Contract Programmer
Рет қаралды 10 М.
Solidity Proxy Contract Example
10:54
James Bachini
Рет қаралды 917
Deploying More Efficient Upgradeable Contracts
40:54
OpenZeppelin
Рет қаралды 25 М.
Minimal Proxy Contract | Solidity (0.7)
10:00
Smart Contract Programmer
Рет қаралды 15 М.
How to create and deploy an ERC-721 (NFT)
21:15
QuickNode
Рет қаралды 35 М.
Uncut Gem: Mastering the Diamond Proxy Pattern [Advanced Proxy Pattern]
27:24
Jesper Kristensen (jtk.eth)
Рет қаралды 4,7 М.
Smart contract design patterns | Noah Citron
46:46
a16z crypto
Рет қаралды 4,1 М.
Upgradable Smart Contracts - UUPS Proxy tutorial
22:49
Shobhit (Web3 Club)
Рет қаралды 11 М.
We may have killed p10k, so I found the perfect replacement.
19:48
Dreams of Autonomy
Рет қаралды 199 М.