Solana Account Model
What is an Account?
Accounts are any place where data is stored on the Solana blockchain. What makes the Solana blockchain unique compared to other blockchains like Ethereum is how this data is stored and managed. Here are the different account categories:
- Program Account — These accounts store executable code and the equivalent of Ethereum smart contracts.
- Storage Account — These accounts store the data connected to programs.
- Token Account — These accounts track an account balance of tokens and allow for transferring or receiving tokens between accounts.
In the Solana blockchain, there is a separation between the program and the data/state of the program. Both are assigned separate accounts but are connected. Comparing this to Ethereum, a smart contract and the data of that smart contract are located in one location on the blockchain. If you were to make a program that counted the number of token transfers that a program made, you would need to create the program to make the transfers as well as another account to store the count of transfers
To take an example from the traditional finance world, you can think of a program like a debit card, your bank as a storage account, and your account balance as a token account. While each of these is connected, they are in separate locations. If you were to lose your debit card, you would not lose your bank account (but maybe the funds in it). Your card is also the only card that can alter the account balance by using it to buy things. Similarly, the program associated with a storage account is the only one that can change the state of the data.
Types of Accounts
There are two types of accounts on the Solana blockchain: executable and non-executable. Programs are executable accounts and store the immutable code of a program.
Data storage and token balances are stored in non-executable accounts as their data can be changed. To control who can change this data, non-executable accounts have an owner program address assigned to them. Other programs can read the data of another account, but if they tried to modify that data, the transaction would fail.
Rent
Storing data on Solana comes with costs, known as rent, paid in Lamports (LAM), fractions of SOL.
Key Points:
- Rent fees are calculated based on account storage size.
- Fees increase with data storage.
- Rent is collected every epoch (approx. 2 days).
- Accounts with zero balance and insufficient rent are removed.
- Holding 2 years' worth of rent makes an account rent-exempt.
Estimating Rent Costs:
Use the Solana CLI rent command:
Solana rent < account size in bytes >
Get:
- Rent per byte - Rent per epoch - Minimum rent-exempt balance
How to Create an Account
To create a Solana account:
Step 1: Generate Key Pair
- Client generates public and private key pair.
Step 2: Register Account
- Client uses System Program::Create Account to: - Register public key - Allocate data storage (up to 10 MB, fixed)
Account Ownership
- Assign owner during account creation - Only owner can modify account data - Default owner: System Program (native Solana program)
System Program Responsibilities
- Create accounts - Allocate data - Assign ownership - Handle Lamport transfers - Token transfers (deduct/credit)
Token Transfer Process
1. User signs transfer instructions with private key 2. System Program: - Deducts tokens from sender - Credits receiver account
Note: Native programs (like System Program) run on all Solana validators.
Interacting with Accounts
Since the program code and data stored by the program are separate accounts, any program can read the data of another account. Any program can also add Lamports to an account but only the owner can subtract them. This is useful when building programs that might need to interact with accounts that it does not own.
When reading an account, you will see this data returned:
Here’s a breakdown of that data:
- Public Key — the public key assigned to this account
- Balance — the amount of SOL owned by this account
- Owner — The address of the program that has ownership of this account
- Executable — If this is an executable account or not
- rent_ epoch — The next epoch in which this account will pay rent
- Length — The size of the account
Conclusion
Creating and interacting with accounts is how anything gets done on Solana. The separation of programs and the data they use is a unique approach to code and state management. Understanding the ownership rules and how programs work within those rules is important to be successful in developing on Solana.
Let us help you safely launch your NFT project