RPC Best Practices
A condensed summary of the 25 most important RPC practices drawn from every page in this section.
-
Never ship production on public RPC: Use a paid provider or self-hosted node with SLA (RPC Providers).
-
Store keys in environment variables: Never commit API keys; proxy sensitive reads through your backend.
-
Pair HTTP and WSS URLs: Subscriptions need
wss://from the same vendor dashboard (WebSocket Subscriptions). -
Set commitment explicitly: Default to
confirmedfor UX;finalizedfor treasury (RPC Basics). -
Null-check getAccountInfo:
value: nullmeans missing account - do not decode blindly (Core RPC Methods). -
Prefer getMultipleAccounts: Batch known pubkeys instead of N serial
getAccountInfocalls. -
Never run unfiltered GPA on mainnet: Always memcmp/dataSize filter or use an indexer (getProgramAccounts & Filters).
-
Chunk large batches: 50-100 accounts per
getMultipleAccountsrequest (Pagination & Efficiency). -
Paginate signatures server-side:
getSignaturesForAddresscursoring belongs in your API, not mobile clients for whales. -
Abort WebSocket subscriptions: Clean up on unmount to avoid connection leaks.
-
Use signatureNotifications for confirms: Prefer subscriptions over 200ms polling loops.
-
Simulate before mainnet sends: Read
unitsConsumedand logs (Priority Fee & Simulation APIs). -
Refresh priority fees per batch:
getRecentPrioritizationFeesstale samples underprice during congestion. -
Add CU headroom: Set compute unit limit to 110% of simulated consumption.
-
Use DAS for wallet NFTs:
getAssetsByOwnerbeats manual metadata GPA (The DAS API). -
Keep DAS and RPC URLs documented: They may differ on provider dashboards.
-
Implement RPC failover: Secondary URL on 429/503 with exponential backoff.
-
Rate-limit your own clients: Protect provider quota from retry storms.
-
Align CLI and app RPC:
solana config getshould matchRPC_URLwhen debugging. -
Cache immutable data only: Short TTL for mint metadata; never cache post-swap balances without invalidation.
-
Monitor slot lag:
getSlotRTT and stall detection alert unhealthy endpoints. -
Avoid heavy getTransaction in browsers: Proxy through indexer for history views.
-
Use jsonParsed selectively: Fall back to
base64+ IDL decode when parser unsupported. -
Plan indexer migration early: If GPA or history scans exceed thousands of rows, start Geyser pipeline (Indexing Basics).
-
Pin @solana/kit 7.0.0: Typed RPC reduces param bugs vs raw fetch.
FAQs
What is the top RPC mistake?
Unfiltered mainnet getProgramAccounts in production - timeouts, cost, and bans.
Public RPC ever OK?
Local prototypes and rare CLI use only - not user-facing mainnet traffic.
How do RPC practices tie to tx landing?
Simulation and priority fee RPCs feed compute budget decisions - see tx optimization section.
Related
- RPC Basics - section entry
- RPC Providers - vendor choice
- Pagination & Efficiency - scale patterns
- Indexing Best Practices - beyond RPC
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.