Core RPC Methods
The essential read methods every Solana client uses: account info, balances, program scans, and batch fetches.
Recipe
Quick-reference recipe card - copy-paste ready.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
await rpc.getAccountInfo(pubkey, { encoding: "base64" }).send();
await rpc.getBalance(pubkey).send();
await rpc.getMultipleAccounts([pk1, pk2]).send();
await rpc.getProgramAccounts(programId, { encoding: "base64" }).send();When to reach for this:
- Hydrating UI with wallet and token balances.
- Fetching a single config account for your program.
- Batch-loading NFT/token accounts for a gallery view.
- Scanning program-owned accounts (with filters - see GPA page).
Working Example
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const SYSTEM_PROGRAM = address("11111111111111111111111111111111");
const wallet = address("YOUR_WALLET_PUBKEY");
const [balance, accountInfo, multi] = await Promise.all([
rpc.getBalance(wallet, { commitment: "confirmed" }).send(),
rpc.getAccountInfo(SYSTEM_PROGRAM, { encoding: "base64" }).send(),
rpc.getMultipleAccounts([wallet, SYSTEM_PROGRAM], {
commitment: "confirmed",
encoding: "base64",
}).send(),
]);
console.log({
lamports: balance.value,
systemExecutable: accountInfo.value?.executable,
multiCount: multi.value?.length,
});What this demonstrates:
getBalancereturns lamports for system-owned wallets.getAccountInforeturns owner, lamports, data, executable flag.getMultipleAccountsbatches up to provider limits in one RPC round trip.
Deep Dive
How It Works
- All methods are JSON-RPC POSTs with
commitmentandencodingoptions. base64encoding is standard for binary program data;jsonParsedworks for some SPL programs on supporting nodes.getProgramAccountswithout filters scans entire program space - expensive on mainnet.- Null
valuemeans account does not exist at chosen commitment.
Method Summary
| Method | Returns | Cost |
|---|---|---|
getAccountInfo | Single account | Low |
getBalance | Lamports only | Low |
getMultipleAccounts | Up to N accounts | Medium |
getProgramAccounts | All matching accounts | High without filters |
TypeScript Notes
// Prefer address() helper for base58 pubkeys
import { address, assertIsAddress } from "@solana/kit";
const mint = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
assertIsAddress(mint);Gotchas
- Unfiltered GPA on mainnet - timeouts and 429s. Fix: memcmp/dataSize filters (getProgramAccounts & Filters).
- Assuming account exists -
value: nullcrashes naive parsers. Fix: null-check before decoding. - jsonParsed everywhere - not all programs supported. Fix: decode with your IDL from
base64. - Huge batch arrays - providers cap
getMultipleAccountslength. Fix: chunk into batches of 100 or per provider docs. - Stale commitment after send - UI shows old balance until
confirmedrefresh. Fix: poll or subscribe after transactions.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
DAS getAsset | NFT/compressed metadata | Custom program accounts |
| Geyser/Yellowstone | Indexer-scale streaming | Simple wallet balance |
solana account CLI | One-off debugging | Production app reads |
| Helius enhanced APIs | Parsed token balances | Provider lock-in unacceptable |
FAQs
What encoding should I use?
base64 for generic program data; jsonParsed when provider documents SPL support for your account type.
How many accounts in getMultipleAccounts?
Depends on provider - chunk 50-100 pubkeys per call as a safe default.
Does getBalance include rent?
Yes - total lamports in the account; token accounts hold separate balances per mint.
Why is getProgramAccounts slow?
Scans all accounts owned by program - always add filters on mainnet.
Can I use these on localnet?
Yes - point RPC URL at http://127.0.0.1:8899.
How do I decode base64 data?
Use Anchor/codama clients or Borsh layouts matching on-chain structs.
What commitment for UI balance?
confirmed after user transactions; processed only for low-stakes live counters.
Is getAccountInfo cached?
No server-side cache guarantees - treat as live read; add your own TTL cache carefully.
How do GPA and GMA differ?
getProgramAccounts scans by owner program; getMultipleAccounts fetches explicit pubkeys you already know.
Do kit 7.0.0 types include encoding enums?
Yes - pass encoding: "base64" in params objects with full TypeScript checking.
Related
- RPC Basics - commitment and transport
- getProgramAccounts & Filters - filtered scans
- Pagination & Efficiency - batching patterns
- The DAS API - asset-specific reads
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.