RPC & Subscriptions
Typed HTTP JSON-RPC and WebSocket subscriptions with @solana/kit 7.0.0.
Search across all documentation pages
Typed HTTP JSON-RPC and WebSocket subscriptions with @solana/kit 7.0.0.
Quick-reference recipe card - copy-paste ready.
import { createSolanaRpc, createSolanaRpcSubscriptions, address } from "@solana/kit";
const rpc = createSolanaRpc(process.env.RPC_URL!);
const balance = await rpc.getBalance(address("PUBKEY")).send();
const ws = createSolanaRpcSubscriptions(process.env.RPC_WSS_URL!);When to reach for this:
import { createSolanaRpc, createSolanaRpcSubscriptions, address } from "@solana/kit";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const rpcSubscriptions = createSolanaRpcSubscriptions("wss://api.devnet.solana.com");
async function watchBalance(owner: string) {
const acct = address(owner);
const { value } = await rpc.getBalance(acct).send();
console.log("initial", value);
const abort = new AbortController();
const stream = await rpcSubscriptions
.accountNotifications(acct, { commitment: "confirmed" })
.subscribe({ abortSignal: abort.signal });
for await (const n of stream) {
console.log("update", n.value.lamports);
}
}What this demonstrates:
.send().AbortController for cleanup.createSolanaRpc wraps JSON-RPC 2.0 with typed methods and responses.createSolanaRpcSubscriptions opens a WebSocket and exposes async iterable notifications.| Method | Use |
|---|---|
getBalance | SOL balance |
getAccountInfo | Raw account data |
getLatestBlockhash | Transaction lifetime |
simulateTransaction | Preflight errors |
sendTransaction | Submit signed tx |
// Pass commitment on reads that power treasury UI
await rpc.getBalance(owner, { commitment: "finalized" }).send();wss:// from provider docs.getAsset needs DAS-enabled hosts. Fix: capability matrix per vendor..send() - RPC builders are lazy until sent. Fix: always chain .send().| Alternative | Use When | Don't Use When |
|---|---|---|
| Yellowstone gRPC | Indexer-scale ingestion | Simple wallet UI |
| Helius webhooks | Server-side event push | Pure browser client |
| HTTP polling | Rare updates | Sub-second balance UI |
| web3.js Connection | Legacy maintenance | Greenfield apps |
Yes - point RPC and wallet at the same cluster.
Avoid in one module - migrate wholesale per route.
Wallets provide signers; kit builds messages.
Lock 7.0.0 in package.json and CI.
Compute budget instructions before send.
Surfpool 0.12.0 or local validator with devnet clones.
Always bigint lamports in kit code.
confirmed for UI; finalized for treasury.
Reads on server; signing in client components.
Simulate, read logs, verify account owners.
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