The Solana RPC API is the primary interface for interacting with the Solana blockchain. It provides a set of JSON-RPC methods that allow developers to read network state, send transactions, simulate execution, and subscribe to real-time updates. Whether you are building a DeFi application, a wallet, or an NFT marketplace, the RPC API is your gateway to the Solana cluster.
This guide covers the core concepts, available methods, and best practices for using the Solana RPC API effectively. We'll also discuss how to choose between public endpoints and managed RPC services for production workloads.
Key takeaways
- The Solana RPC API uses JSON-RPC 2.0 over HTTP and WebSocket for request-response and subscription methods.
- Public endpoints like api.mainnet.solana.com are rate-limited and not suitable for production apps.
- Key RPC methods include getAccountInfo, getBalance, getTransaction, sendTransaction, and getProgramAccounts.
- State commitment levels (processed, confirmed, finalized) control how recently data is considered final.
- For production, use a managed RPC provider like OnFinality to get dedicated nodes, higher throughput, and reliable uptime.
- WebSocket subscriptions enable real-time updates for accounts, logs, and transactions.
- Optimize RPC usage by caching responses, batching requests, and avoiding polling where possible.
What is the Solana RPC API?
The Solana RPC API is a JSON-RPC 2.0 interface that allows applications to communicate with Solana nodes. It exposes methods for querying account balances, retrieving transaction history, sending transactions, and subscribing to events via WebSocket. Every interaction with the Solana blockchain—whether from a wallet, dApp, or backend service—goes through an RPC endpoint.
Solana's architecture is designed for high throughput, and the RPC API reflects that with methods optimized for performance. However, public RPC endpoints are shared infrastructure and come with rate limits that can hinder production applications. For reliable access, many developers turn to managed RPC providers like OnFinality.
- JSON-RPC 2.0 over HTTP POST for request-response calls
- WebSocket connections for real-time subscriptions
- Supports mainnet, devnet, and testnet clusters
- Methods cover accounts, tokens, transactions, blocks, and cluster info
Access high-performance Solana RPC endpoints with dedicated node options. Start building on mainnet, devnet, or testnet. Explore Solana RPC.
Solana RPC Endpoints and Clusters
Solana operates three public clusters: mainnet-beta, devnet, and testnet. Each has a public RPC endpoint, but these are rate-limited and not recommended for production use. The official endpoints are:
For development and testing, devnet and testnet provide free access with faucets for test SOL. Production applications should use a dedicated RPC provider to ensure reliability and scalability.
| Criterion | What to check | Why it matters |
|---|---|---|
| Cluster | Public Endpoint | Use for testing or light usage |
| Mainnet | https://api.mainnet.solana.com | Production network with real SOL |
| Devnet | https://api.devnet.solana.com | Developer testing with free SOL from faucet |
| Testnet | https://api.testnet.solana.com | Validator testing, less stable |
Not sure which Solana RPC provider fits your needs? Read our guide on choosing the right infrastructure. Read the guide.
Key Solana RPC Methods
Each method accepts parameters and returns a JSON response. For example, getBalance takes a base58-encoded public key and returns the lamport balance. Always check the official documentation for parameter details and response formats.
- Accounts: getAccountInfo, getBalance, getMultipleAccounts
- Transactions: getTransaction, sendTransaction, simulateTransaction
- Tokens: getTokenAccountBalance, getTokenAccountsByOwner, getTokenSupply
- Blocks: getBlock, getBlocks, getBlockHeight
- Cluster: getEpochInfo, getSlot, getHealth
- Programs: getProgramAccounts (heavy method, use with filters)
For high-throughput applications, dedicated Solana nodes provide isolated resources and consistent performance. Learn about dedicated nodes.
State Commitment and Finality
Solana RPC methods accept an optional commitment parameter that controls how recently the data must be confirmed. The three levels are:
Choosing the right commitment level is crucial for your application. For example, a wallet might use 'confirmed' for transaction status, while a block explorer might use 'finalized' for historical data.
| Criterion | What to check | Why it matters |
|---|---|---|
| Commitment | Description | Trade-off between speed and finality |
| processed | Node's most recent block (may be rolled back) | Fastest, but not final |
| confirmed | Block voted by cluster (supermajority) | Good balance for most apps |
| finalized | Block confirmed by full cluster (>= 32 confirmations) | Maximum safety, slower |
OnFinality supports Solana mainnet, devnet, and testnet, plus 30+ other blockchains. See networks.
WebSocket Subscriptions
In addition to HTTP methods, the Solana RPC API supports WebSocket subscriptions for real-time updates. You can subscribe to account changes, program logs, transaction confirmations, and slot updates. This is more efficient than polling.
To use subscriptions, connect to the WebSocket endpoint (e.g., wss://api.mainnet.solana.com) and send a JSON-RPC subscribe request. The server will push notifications until you unsubscribe.
- accountSubscribe: Notify when an account's data changes
- logsSubscribe: Listen to program logs
- signatureSubscribe: Get notified when a transaction is confirmed
- slotSubscribe: Receive updates when a new slot is produced
Best Practices for Using the Solana RPC API
For high-throughput applications, consider dedicated nodes. OnFinality offers dedicated Solana nodes with isolated resources, ensuring consistent performance even under heavy load.
- Avoid polling for data that changes infrequently; use WebSocket subscriptions instead.
- Cache responses for expensive methods like getProgramAccounts and getSignaturesForAddress.
- Batch requests when possible using JSON-RPC batch calls.
- Use a managed RPC provider for production to avoid rate limits and ensure uptime.
- Monitor your RPC usage and set up alerts for error rates or latency spikes.
- Test on devnet before deploying to mainnet.
Choosing a Solana RPC Provider
Public RPC endpoints are fine for development but insufficient for production. Managed providers offer higher rate limits, dedicated nodes, enhanced APIs, and support. When evaluating providers, consider:
OnFinality provides Solana RPC endpoints with flexible plans, including shared and dedicated node options. You can get started quickly with a free tier and scale as your application grows.
| Criterion | What to check | Why it matters |
|---|---|---|
| Feature | Why It Matters | Impact on your app |
| Rate limits | Requests per second allowed | Limits your throughput |
| Uptime SLA | Guaranteed availability | Reliability for users |
| Dedicated nodes | Isolated infrastructure | Consistent performance |
| Enhanced APIs | Additional endpoints beyond standard RPC | Simplify development |
| Global coverage | Geographic distribution of endpoints | Lower latency worldwide |
FAQ
What is the difference between Solana RPC HTTP and WebSocket methods?
HTTP methods are request-response: you send a request and get a response. WebSocket methods allow you to subscribe to events and receive push notifications when data changes, which is more efficient for real-time updates.
How do I get free SOL for testing on Solana devnet?
You can use the Solana Faucet at https://faucet.solana.com to request devnet SOL. Some RPC providers also offer faucet endpoints.
What is a 'heavy' RPC method on Solana?
Heavy methods like getProgramAccounts can consume significant node resources because they scan large account spaces. Always use filters (e.g., by data size or owner) to limit the result set.
Can I use the public Solana RPC endpoint for production?
Public endpoints are rate-limited and shared among all users, making them unsuitable for production. Use a managed RPC provider like OnFinality for reliable, scalable access.
How do I send a transaction via the Solana RPC API?
Use the sendTransaction method with a signed transaction in base58 or base64 encoding. The method returns the transaction signature if successful.
Related resources
Originally published at OnFinality.
Top comments (0)