So when increasing the data size of my account I of course would add some additional fields in my Struct. So on the basis of new Struct I won't be able to deserialize the previous data. Do i need to keep a copy of the previous struct to deserialize the data and use it to add the data to the new struct but the publicKey would be of the created account? In doing so the previous struct would be used to deserialize the older accounts and the new struct would be consuming the data and adding more info to the account while the address remains the same?

1 Answer 1


Yes, you would basically do an account migrate on read. As a best practice, including a version field in the original struct would make it easier to read that field as a discriminator on when to convert from the old to new.

There is a simple example in the Solana cookbook that demonstrated migrating structs. It was written prior to the realloc feature but is generally the same approach: Solana Cookbook

  • I see, alright and once the data would added to the account, of course I would need to deposit more sol to the account for it to be rent exempt. I would have to transfer that sol from the client side into the account for it to be able to accommodate for the increased size rent? Commented Jul 20, 2022 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.