๐ฆ Accounts
On Solana, accounts are the units of on-chain state. They hold SOL (lamports), arbitrary data, and an owner (a program that can modify them). There are no โcontract storageโ slots like on the EVM โ everything is an account.
๐ฏ Why Accounts Matter
- Everything is an account โ Program code, user data, token balances, NFT metadata
- Explicit in instructions โ Every instruction lists which accounts it reads/writes; the runtime enforces permissions
- Rent โ Accounts must hold enough SOL to be rent-exempt or they can be reclaimed
๐ Account Structure
From the Solana docsย :
| Field | Description |
|---|---|
| lamports | Balance in lamports (1 SOL = 10^9 lamports) |
| owner | Program ID that can modify this account |
| data | Opaque byte array (layout defined by the owner program) |
| executable | Whether the account is program code |
| rent_epoch | Used for rent calculation |
Only the owner program can change the accountโs data or assign a new owner. Clients and other programs pass account references in each instruction.
๐ Reading an Account (Node / @solana/web3.js)
import { Connection, PublicKey } from "@solana/web3.js";
const connection = new Connection("https://api.devnet.solana.com");
const address = new PublicKey("YourAccountPubkey...");
const accountInfo = await connection.getAccountInfo(address);
if (accountInfo) {
console.log("Owner:", accountInfo.owner.toBase58());
console.log("Lamports:", accountInfo.lamports);
console.log("Data length:", accountInfo.data.length);
// Data layout depends on the program (e.g. Metaplex, SPL Token)
}๐ Account Sizes and Rent
- Rent-exempt minimum โ Accounts below a size threshold must hold enough lamports to be rent-exempt. See rentย .
- Closing โ When an account is no longer needed, a program can close it and send the lamports to a specified account (e.g. user).
๐ Resources
Last updated on