RPC Basics
10 examples to get you started with Solana JSON-RPC - 7 basic and 3 intermediate.
Search across all documentation pages
10 examples to get you started with Solana JSON-RPC - 7 basic and 3 intermediate.
@solana/kit 7.0.0 for TypeScript examplesnpm install @solana/kit@7.0.0Solana nodes speak JSON-RPC 2.0 over HTTP POST.
curl https://api.devnet.solana.com -s -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getHealth"
}'camelCase like getBalance, getSlot.result or error with code and message.Type-safe reads with @solana/kit 7.0.0.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const health = await rpc.getHealth().send();
console.log(health);createSolanaRpc wraps fetch-based JSON-RPC calls..send() executes the request and returns typed results.Related: Core RPC Methods - common methods
Fastest reads - may roll back on forks.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const slot = await rpc.getSlot({ commitment: "processed" }).send();
console.log("processed slot:", slot);Default for most application reads.
const balance = await rpc
.getBalance(address("11111111111111111111111111111111"), {
commitment: "confirmed",
})
.send();
console.log("lamports:", balance.value);confirmed on sends before showing success UI.Safest reads for treasury and accounting.
const account = await rpc
.getAccountInfo(address("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), {
commitment: "finalized",
encoding: "base64",
})
.send();
console.log(account.value?.lamports);Providers return HTTP 429 when throttled.
curl -i https://api.devnet.solana.com -s -X POST -H "Content-Type: application/json" -d '
{"jsonrpc":"2.0","id":1,"method":"getSlot"}' | head -20Related: RPC Providers - provider comparison
Terminal commands hit the same JSON-RPC as your app.
solana config set --url https://api.devnet.solana.com
solana slotsolana slot maps to getSlot.RPC_URL.Reduce round trips by batching JSON-RPC in one HTTP body.
import { createSolanaRpc, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const [slot, blockHeight] = await Promise.all([
rpc.getSlot().send(),
rpc.getBlockHeight().send(),
]);
console.log({ slot, blockHeight });Promise.all still uses multiple HTTP requests unless provider supports batch arrays.getMultipleAccounts over N getAccountInfo calls.Related: Pagination & Efficiency - efficient reads
Subscriptions need WebSocket transport.
# HTTP for one-shot reads
curl https://api.devnet.solana.com ...
# WS for accountSubscribe (kit or ws client)accountSubscribe, logsSubscribe require persistent socket.Related: WebSocket Subscriptions - live updates
Digital Asset Standard API extends reads for NFTs and compressed assets.
// DAS methods (e.g. getAsset) live on provider DAS-enabled endpoints
// Standard getAccountInfo still underlies raw account bytesgetAccountInfo for custom program accounts.Related: The DAS API - asset 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.
Reviewed by Chris St. John·Last updated Jul 16, 2026