On Solana, all data is stored in what are referred to as "accounts”. The waydata is organized on Solana resembles akey-value store,where each entry in the database is called an "account".
Accounts
Key Points #
Accounts can store up to 10MB of data, which can consist of either executableprogram code or program state.
Accounts require a rent deposit in SOL, proportional to the amount of datastored, which is fully refundable when the account is closed.
Every account has a program "owner". Only the program that owns an account canmodify its data or deduct its lamport balance. However, anyone can increasethe balance.
Programs (smart contracts) are stateless accounts that store executable code.
Data accounts are created by programs to store and manage program state.
Native programs are built-in programs included with the Solana runtime.
Sysvar accounts are special accounts that store network cluster state.
Account #
Each account is identifiable by its unique address, represented as 32 bytes inthe format of an Ed25519 PublicKey
. You can thinkof the address as the unique identifier for the account.
Account Address
This relationship between the account and its address can be thought of as akey-value pair, where the address serves as the key to locate the correspondingon-chain data of the account.
AccountInfo #
Accounts have amax size of 10MB(10 Mega Bytes) and the data stored on every account on Solana has the followingstructure known as theAccountInfo.
AccountInfo
The AccountInfo
for each account includes the following fields:
data
: A byte array that stores the state of an account. If the account is aprogram (smart contract), this stores executable program code. This field isoften referred to as the "account data".executable
: A boolean flag that indicates if the account is a program.lamports
: A numeric representation of the account's balance inlamports, the smallest unit of SOL (1 SOL = 1billion lamports).owner
: Specifies the public key (program ID) of the program that owns theaccount.
As a key part of the Solana Account Model, every account on Solana has adesignated "owner", specifically a program. Only the program designated as theowner of an account can modify the data stored on the account or deduct thelamport balance. It's important to note that while only the owner may deduct thebalance, anyone can increase the balance.
Info
To store data on-chain, a certain amount of SOL must be transferred to anaccount. The amount transferred is proportional to the size of the data storedon the account. This concept is commonly referred to as “rent”. However, youcan think of "rent" more like a "deposit" because the SOL allocated to anaccount can be fully recovered when the account is closed.
Native Programs #
Solana contains a small handful of native programs that are part of thevalidator implementation and provide various core functionalities for thenetwork. You can find the full list of native programshere.
When developing custom programs on Solana, you will commonly interact with twonative programs, the System Program and the BPF Loader.
System Program #
By default, all new accounts are owned by theSystem Program.The System Program performs several key tasks such as:
- New Account Creation:Only the System Program can create new accounts.
- Space Allocation:Sets the byte capacity for the data field of each account.
- Assign Program Ownership:Once the System Program creates an account, it can reassign the designatedprogram owner to a different program account. This is how custom programs takeownership of new accounts created by the System Program.
On Solana, a "wallet" is simply an account owned by the System Program. Thelamport balance of the wallet is the amount of SOL owned by the account.
System Account
Info
Only accounts owned by the System Program can be used as transaction feepayers.
BPFLoader Program #
TheBPF Loaderis the program designated as the "owner" of all other programs on the network,excluding Native Programs. It is responsible for deploying, upgrading, andexecuting custom programs.
Sysvar Accounts #
Sysvar accounts are special accounts located at predefined addresses thatprovide access to cluster state data. These accounts are dynamically updatedwith data about the network cluster. You can find the full list of SysvarAccounts here.
Custom Programs #
On Solana, “smart contracts” are referred to asprograms. A program is an account that containsexecutable code and is indicated by an “executable” flag that is set to true.
For a more detailed explanation of the program deployment process, refer to theDeploying Programs page of this documentation.
Program Account #
When new programs aredeployedon Solana, technically three separate accounts are created:
- Program Account: The main account representing an on-chain program. Thisaccount stores the address of an executable data account (which stores thecompiled program code) and the update authority for the program (addressauthorized to make changes to the program).
- Program Executable Data Account: An account that contains the executablebyte code of the program.
- Buffer Account: A temporary account that stores byte code while a programis being actively deployed or upgraded. Once the process is complete, the datais transferred to the Program Executable Data Account and the buffer accountis closed.
For example, here are links to the Solana Explorer for the Token ExtensionsProgram Accountand its correspondingProgram Executable Data Account.
Program and Executable Data Accounts
For simplicity, you can think of the "Program Account" as the program itself.
Program Account
Info
The address of the "Program Account" is commonly referred to as the “ProgramID”, which is used to invoke the program.
Data Account #
Solana programs are "stateless", meaning that program accounts only contain theprogram's executable byte code. To store and modify additional data, newaccounts must be created. These accounts are commonly referred to as “dataaccounts”.
Data accounts can store any arbitrary data as defined in the owner program'scode.
Data Account
Note that only the System Program cancreate new accounts. Once the System Program creates an account, it can thentransfer ownership of the new account to another program.
In other words, creating a data account for a custom program requires two steps:
- Invoke the System Program to create an account, which then transfersownership to a custom program
- Invoke the custom program, which now owns the account, to then initialize theaccount data as defined in the program code
This data account creation process is often abstracted as a single step, butit's helpful to understand the underlying process.