Summary
Solana RPC endpoints let your dApp read chain state, submit transactions, and subscribe to real-time updates. This guide explains how Solana RPC works, how to connect to public and dedicated endpoints, and what to evaluate when choosing infrastructure for production.
Quick recommendation: how to pick a Solana RPC endpoint
If you are building a small script or testing on Devnet, a public endpoint is enough. If you are running a production dApp, a shared or dedicated RPC provider gives you more consistent performance, higher rate limits, and WebSocket support for real-time subscriptions. Start with a managed provider like OnFinality's Solana RPC to avoid the operational overhead of running your own validator or RPC node.
What is an RPC for Solana?
Solana RPC (Remote Procedure Call) is the interface that lets your application talk to the Solana blockchain. Through JSON-RPC, you can query account balances, fetch transaction details, send signed transactions, and subscribe to account or program updates. Solana's RPC API is HTTP-based, with WebSocket support for streaming updates.
Unlike Ethereum's JSON-RPC, Solana uses its own set of methods, such as getBalance, getLatestBlockhash, and sendTransaction. The endpoint you use determines the quality of service: public endpoints are free but often rate-limited, while managed providers offer higher throughput and reliability.
Solana RPC endpoint options
| Endpoint type | Use case | Considerations |
|---|---|---|
| Public endpoint | Development, testing, low-volume calls | Rate-limited, may be unreliable for production |
| Shared RPC provider | Production dApps with moderate traffic | Better reliability, higher rate limits, WebSocket support |
| Dedicated node | High-throughput applications, custom needs | Full control, highest performance, more cost |
OnFinality offers both shared and dedicated Solana RPC options. You can start with the public endpoint for testing and upgrade to a dedicated node when your traffic grows.
How to connect to Solana RPC
To connect to Solana RPC, you need an endpoint URL. OnFinality's public Solana endpoint is https://solana.api.onfinality.io/public. For WebSocket subscriptions, use wss://solana.api.onfinality.io/public-ws.
Here's a basic example using curl to get the latest blockhash:
curl https://solana.api.onfinality.io/public \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getLatestBlockhash"}'
In JavaScript, you can use the @solana/web3.js library:
import { Connection, clusterApiUrl } from '@solana/web3.js';
const connection = new Connection('https://solana.api.onfinality.io/public', 'confirmed');
async function getBalance(address) {
const balance = await connection.getBalance(address);
console.log(`Balance: ${balance / 1e9} SOL`);
}
For WebSocket subscriptions, use the wss endpoint:
import { Connection, PublicKey } from '@solana/web3.js';
const connection = new Connection('wss://solana.api.onfinality.io/public-ws', 'confirmed');
const account = new PublicKey('...');
connection.onAccountChange(account, (accountInfo) => {
console.log('Account changed:', accountInfo);
});
What to evaluate when choosing a Solana RPC provider
When comparing RPC providers for Solana, consider these factors:
- Throughput and rate limits: How many requests per second can you send? Public endpoints often limit you to a few requests per second, which is too low for production.
- WebSocket support: Real-time subscriptions require a WebSocket endpoint. Check if the provider offers stable WebSocket connections.
- Archive data: If you need historical state, look for providers that offer archive nodes.
- Geographic distribution: Low latency matters for time-sensitive applications. Providers with global edge nodes reduce round-trip time.
- Uptime and reliability: Look for providers with a track record of high availability, but be wary of absolute guarantees.
OnFinality's RPC pricing page outlines the options, and you can see the full list of supported networks on the networks page.
Common pitfalls when using Solana RPC
- Rate limiting: Public endpoints often return 429 errors when you exceed limits. Implement retry logic with exponential backoff.
- Transaction confirmation: Solana uses
confirmedorfinalizedcommitment levels. Useconfirmedfor most use cases, but understand the trade-offs. - WebSocket disconnections: WebSocket connections can drop. Implement reconnection logic to maintain subscriptions.
- Blockhash expiry: Transactions must reference a recent blockhash. Fetch a new blockhash before sending each transaction.
Debugging Solana RPC calls
When an RPC call fails, check the error code and message. Common errors include:
-32000– Server error, often due to invalid parameters.-32001– Resource exhaustion, such as rate limiting.-32002– Unsupported method.
Use the getHealth method to check if the node is healthy:
curl https://solana.api.onfinality.io/public \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}'
If you get a ok response, the node is healthy. If not, try a different endpoint or contact your provider.
When to use a dedicated Solana node
A dedicated node gives you exclusive access to an RPC server. This is useful when:
- You have high throughput requirements that exceed shared limits.
- You need custom configuration, such as enabling specific features.
- You want to avoid noisy neighbors that can affect performance.
OnFinality offers dedicated nodes for Solana. You can provision a node in minutes and get a private endpoint.
Key Takeaways
- Solana RPC is the standard way to interact with the Solana blockchain.
- Public endpoints are fine for development, but production apps need reliable managed infrastructure.
- Evaluate providers based on throughput, WebSocket support, archive data, and geographic coverage.
- OnFinality provides both shared and dedicated Solana RPC options with a public endpoint for testing.
Frequently Asked Questions
What is the difference between a public and a dedicated Solana RPC endpoint?
A public endpoint is shared among many users and often rate-limited. A dedicated endpoint is provisioned exclusively for your project, offering higher performance and reliability.
Can I use Solana RPC for free?
Yes, you can use public endpoints for free, but they are not suitable for production workloads due to rate limits and potential downtime.
How do I get a Solana RPC endpoint?
You can use a public endpoint like https://solana.api.onfinality.io/public or sign up for a managed provider to get a dedicated endpoint.
What is the best Solana RPC provider?
The best provider depends on your needs. Compare factors like throughput, WebSocket support, and pricing. OnFinality offers competitive options for both shared and dedicated nodes.
How do I monitor Solana RPC performance?
Use tools like Prometheus to track request latency and error rates. You can also use Solana's getHealth method to check node status.
Can I use WebSocket with Solana RPC?
Yes, Solana supports WebSocket for real-time subscriptions. Use the wss endpoint provided by your RPC provider.
What is the difference between Solana Devnet and Mainnet RPC?
Devnet is a test network with free SOL for development. Mainnet is the production network with real assets. Use Solana Devnet for testing and Mainnet for production.
How do I choose between a shared and a dedicated Solana node?
If your application has moderate traffic, a shared node is cost-effective. If you need high throughput or custom configuration, a dedicated node is better.
What are the common Solana RPC error codes?
Common errors include -32000 for invalid parameters, -32001 for resource exhaustion, and -32002 for unsupported methods. Refer to Solana's documentation for a full list.
How can I get started with Solana RPC?
Start with the public endpoint and a simple curl request. Then, integrate the @solana/web3.js library into your application. For production, consider a managed provider like OnFinality.