(#26) What are Solana Accounts?
Just like a file on a computer, programs can change bytes in accounts.
What are Solana Accounts?
Accounts within Solana are used to store state. They are an essential building block for developing on Solana - Official Documentation
There are 3 kinds of accounts on Solana:
Data accounts store data
Program accounts store executable programs
Native accounts that indicate native programs on Solana such as System, Stake, and Vote
Within data accounts, there are 2 types:
System owned accounts
PDA (Program Derived Address) accounts
Each account has an address (usually a public key) and an owner (address of a program account). Here is an example:
Each account element is a metadata set, so the protocol can easily understand the account’s type and additional information. Metadata consists of:
public key = the accounts address
balance = balance of SOL (also called ‘lamports’ smaller denomination of SOL)
💡 1 lamport is equivalent to one billionth of a SOL token
owner = this is the address of the program that owns the account
executable = a boolean variable that indicates if the account contains executable code
💡 Solana account types are of two main types of accounts: executable and non-executable. This is because Solana programs do not store state like Ethereum smart contracts do, so it needs to separate both type of actions.
💡 If marked as executable the data within this account is actually a program. its rust code that has been serialized down to bytes and it can be executed on the runtime as a smart contract or program.
rent epoch = indicates the next epoch at which the account will owe rent
💡 Every account pays a rent fee to use memory on the blockchain, if an account is a certain amount of storage size, it has to actually pay for that storage size.
💡 An account that maintains a minimum balance equivalent to 2 years of rent fees is exempt. If not, it is charged when it is referenced by a transaction or at every epoch, which currently equates to two days. If an account does not contain the minimum amount of SOL to be rent exempt, its data is deleted from the chain.
Programs use these mutable buffers to persist data such as currency prices, token balances, or exchange orders. Just like a file on a computer, programs can change bytes in accounts.
This core concept is credited to Pencilflip