Is that meaning the logic contract’s state variables will be initialized and stored in proxy contract’s context after the first calling from proxy to logic contract?
Hi @uua,
The state variables in an upgradeable contract are initialized via an initialize
function.
I suggest looking at the following documentation: https://docs.openzeppelin.com/learn/upgrading-smart-contracts#how-upgrades-work
Feel free to ask any questions that you need.
Thanks for replying. I’ve read the recommended article. Below is what I’ve known:
the proxy contract stores the state variables and the logic contract stores the implementation code. And regarding the unstructured proxy pattern zeppelin used, the proxy contract can define its own state variables but need to store them in the randomized slot. The logic contract can define different state variables and functions to match its logic affairs.
basing on the understanding of the unstructured proxy pattern, I want to confirm that the proxy contract will store all of the state variables or not even though I didn’t define any of them used in the logic contract? And how does it achieve? Would you mind telling me are there any interfaces or tools able to check a contract’s state variables if you know?
Hi @uua,
The implementation contract defines the state variables and the state is in the proxy contract.
the proxy is a simple contract that just delegates all calls to an implementation contract. A delegate call is similar to a regular call, except that all code is executed in the context of the caller, not of the callee.
For example, when we call the store
function of our upgradeable contract, the value is stored in the proxy. https://docs.openzeppelin.com/learn/upgrading-smart-contracts#upgrading-a-contract-via-plugins
We can use getStorageAt
on the proxy to check the value.
https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html?highlight=getstorageat#getstorageat