Account Types
Anchor Account Type Examples
Minimal reference examples for Anchor account types.
See the account types source code for implementation details.
Persistence on exit
Typed accounts (Account, InterfaceAccount, AccountLoader,
LazyAccount, Migration, also when wrapped in Box or Option) are
written back to the account data when the instruction returns if the account
is still owned by the program and has not been closed. If ownership moved
during the instruction, for example because the account was reassigned via
CPI, the account is not written: exit succeeds when the account data already
matches the in-memory value and fails with AccountOwnedByWrongProgram
otherwise. Call exit before such a CPI to persist pending changes.
Account Types
Account<'info, T>
Description: Account container that checks ownership on deserialization
Examples: Github
|
Solpg
AccountInfo<'info>
Description: AccountInfo can be used as a type but Unchecked Account should be
used instead
Examples: Github
|
Solpg
AccountLoader<'info, T>
Description: Type facilitating on demand zero copy deserialization
Examples: Github
|
Solpg
Box<Account<'info, T>>
Description: Box type to save stack space
Examples: Github
|
Solpg
Interface<'info, T>
Description: Type validating that the account is one of a set of given
Programs
Examples: Github
|
Solpg
InterfaceAccount<'info, T>
Description: Account container that checks ownership on deserialization
Examples: Github
|
Solpg
Option<Account<'info, T>>
Description: Option type for optional accounts
Examples: Github
|
Solpg
Program<'info, T>
Description: Type validating that the account is the given Program
Examples: Github
|
Solpg
Signer<'info>
Description: Type validating that the account signed the transaction
Examples: Github
|
Solpg
SystemAccount<'info>
Description: Type validating that the account is owned by the system program
Examples: Github
|
Solpg
Sysvar<'info, T>
Description: Type validating that the account is a sysvar and deserializing it
Examples: Github
|
Solpg
UncheckedAccount<'info>
Description: Explicit wrapper for AccountInfo types to emphasize that no checks
are performed
Examples: Github
|
Solpg
Migration<'info, From, To>
Description: Account container that handles schema migrations from one account type (From) to another (To). During deserialization, the account must be in the From format. On instruction exit, the account must be migrated to the To format, which is then serialized. Typically used with the realloc constraint to resize accounts during migration.
Checks:
Account.info.owner == From::owner()- Account is initialized (not owned by system program with 0 lamports)
- Account deserializes as
Fromtype
Usage patterns: