State migration

Hey there

I am thinking about state migration upon a contract upgrade. Let’s say your State structure changes for the next update. You will need to load the current state using the host functions deserialize it using the old Type, and then write it back, serializing it with the new Type.

Is there an example somewhere in your codebase for this?

Have you had a look at the Smart Contract Upgrade tutorial? It also links to this code. The shape of the state in that code is the same but perhaps you can figure out how to do it from the tutorial.

1 Like

But how to migrate, when the State is not that trivial, when it derives HasStateApi to store StateMap inside?