📦 We're going to store data in a Solana account. 📝
Solana accounts are used to store persistent state. This means that the data stays on the blockchain until the account is closed.
In this example, we demonstrate how to:
- Define a data structure: We create an
AddressInfostruct to store a name, house number, street, and city. - Calculate required space: We determine how much memory (bytes) the account needs to store our structure.
- Initialize the account: We allocate the space and write the initial data.
- Anchor: Uses
#[account]and#[derive(InitSpace)]to automate space calculation. - Native: Manually calculates space and uses
Borshfor serialization. - Pinocchio: A lightweight approach to account data management.
Each implementation shows how to handle fixed-size data and strings with maximum lengths.