Account Anatomy

Everything is an Account

Just as in UNIX, where "everything is a file", in Solana "everything is an account". In other words, an account is a memory buffer that functions similarly to a file in a file system. The main purpose of an account is to store state between instructions and transactions. Each account is identified by an address (a public key) and Solana’s account system can therefore be viewed as key-value database.

Note

The key may be one of the following:

Account Anatomy

Account Layout

1. Lamports

  • The account balance is held in lamports.
  • 1 lamport = 10−9 SOL.

2. Data

  • Vector of bytes.
  • The maximum account data size is 10 MB.

Warning

For PDAs, the limit is 10 KB at the time of creation, but they can later be resized to a maximum of 10 MB.

3. Owner

  • The owner is either a program ID or a loader in case of an executable account.
  • All new accounts are owned by the System program which allows:
    • Transfer of lamports.
    • Data allocation.
    • Assignment of ownership to a different program ID.

Info

Program is granted write access only if the owner matches its ID (program owns the account).

Important

An account is always owned either by a program or a loader.

4. Executable

  • Turning a non-executable account into an executable one is a one-way only operation.
  • The owner of such an account is a loader that will load the code from the data field of the account and start executing it if invoked.

Note

Account becomes read-only it is made executable.

5. Rent Epoch

  • To maintain an account on Solana, a fee called rent has to be paid periodically.
  • An account is considered rent-exempt if it holds at least two years’ worth of rent.
  • Every epoch runtime checks whether the account should pay rent or is rent-exempt.

Account Types

There are 3 types of Solana accounts:

  1. Data accounts: These accounts serve as containers for storing and retrieving data.
  2. Program accounts: These accounts store user-deployed executable bytecode.
  3. Native accounts: These accounts hold Solana's built-in programs such as the System program, the BPF Loader, and others.