I am using OpenZeppelin library for upgradeable smart contract. I am facing an issue, after i deploy new upgradeable contract use OpenZeppelin, how i can migrate data from current smart contract to new one?
Hi @minhchau2611,
Welcome to the community
There shouldn’t be a need to migrate data as the state is in the proxy contract and when we upgrade we only change the logic contract.
If you deployed a contract as kind upgradeable using the OpenZeppelin CLI, then when you have created (and tested) the new version of the contract, you can use npx oz upgrade
. Though I recommend that you test this locally, and then on a public testnet before doing this on mainnet.
See the Learn guide Upgrading a Contract using the CLI for an example.
Please ask all the questions that you need.
Thank you for your information
Hi @minhchau2611,
I just wanted to check if that answered your question or if you needed more information?
I suggest reading How Upgrades Work
Hi @abcoathup,
Currently, i am running a regular smart contact and it has more data on my production. I want to apply upgradeable contract, after deploy it, how i can migrate data from current contract ( on my production) to upgradeable contract, that is my issue i need to solve
Hi @minhchau2611,
I understand you now. You want to migrate data from a regular contract to an upgradeable contract.
You will need to create migration code to setup the new contract. You may even want to create a contract to do the migration which reads from the old contract and updates the new contract. Though it depends what data and how much you have stored as this could be quite an expensive process (especially given current gas prices).
Thank you for your advice