Does contract data persist after upgrade?

Apologies for what I feel like is an extremely basic and ignorant question, but I was unable to find a cogent answer.

I’m looking in to ERC721 (and its enumerable extension), but also want to build for future upgradeability via Proxies.

Do the minted tokens from ContractA automatically exist in ContractB after upgrade? Or do they belong to the Proxy contract and therefore this question is moot?

1 Like

Hi @EvilJordan,

Welcome to the community :wave:

All questions are good. Please ask all the questions that you need. It improves the knowledge base of the community and can be used to improve the documentation too.


Upgrades allow us to change the contract code, while preserving the state, balance, and address.

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. Any reads or writes to the contract storage will read or write from the proxy’s own storage.

This allows us to decouple a contract’s state and code: the proxy holds the state, while the logic (implementation) contract provides the code. And it also allows us to change the code by just having the proxy delegate to a different implementation contract.

In your example the Proxy points to logic Contract A and when upgraded the Proxy points to logic Contract B but the state is held with the Proxy contract.

I suggest reading the How Upgrades Work section of the Learn guides.

I would also encourage you to try it out yourself following the Upgrading a Contract using the CLI section of the Learn guides.

One thing to note, is that if you are using OpenZeppelin Contracts with upgradeable contracts you need to use @openzeppelin/contracts-ethereum-package, which is an official fork of OpenZeppelin Contracts that has been modified to use initializers instead of constructors. (see: https://docs.openzeppelin.com/upgrades/2.6/writing-upgradeable#use-upgradeable-packages)

If you are building an ERC721, I would suggest looking at the upcoming release of OpenZeppelin Contracts 3.0. The latest release candidate is: OpenZeppelin Contracts v3.0 final release candidate This has improvements for ERC721 such as automatic token URI.

1 Like

Such an amazing, thorough answer. STATE persists because it’s stored in the Proxy. THANK YOU!!

1 Like

Hi @EvilJordan,

I like your much more succinct answer :smile:

STATE persists because it’s stored in the Proxy.

Glad to be of help. If you get a chance it would be great if you could introduce yourself.

Feel free to ask all the questions that you need.