Summary
Solana's JSON-RPC API is the standard way for applications to interact with the network—querying accounts, submitting transactions, and subscribing to real-time updates. This article explains the core methods, how to connect to an endpoint, and common pitfalls to avoid when building on Solana.
Quick Answer: What Is Solana JSON-RPC?
Solana JSON-RPC is an HTTP and WebSocket API that lets your application read and write data on the Solana blockchain. It follows the JSON-RPC 2.0 specification, meaning you send a JSON object with a method and params, and the node replies with a JSON result or error.
Most developers use it for three things:
- Querying state – account balances, token holdings, transaction details, and block data.
- Sending transactions – serializing and submitting signed instructions.
- Subscribing to updates – real-time notifications for account changes, logs, and slot updates.
If you are building a wallet, explorer, trading bot, or any dApp that needs live Solana data, JSON-RPC is the interface you will use.
Decision Guide: Public Endpoint vs. Dedicated Node
Before you write your first request, decide which endpoint type fits your workload. The choice affects reliability, rate limits, and how much infrastructure you manage.
| Workload | Public endpoint | Dedicated node |
|---|---|---|
| Prototyping, hackathon | ✅ Good | Overkill |
| Production dApp with moderate traffic | ⚠️ Possible but risky | ✅ Recommended |
| High-frequency trading, indexer | ❌ Not suitable | ✅ Required |
Heavy getProgramAccounts calls | ❌ Often rate-limited | ✅ Better isolation |
| WebSocket subscriptions at scale | ⚠️ Limited connections | ✅ Dedicated connections |
Public endpoints are free and convenient for testing. OnFinality offers a public Solana endpoint at https://solana.api.onfinality.io/public and a WebSocket at wss://solana.api.onfinality.io/public-ws. However, public endpoints are shared, so they can throttle or block heavy usage.
Dedicated nodes give you a private RPC endpoint with your own rate limits and resources. They are the right choice when you need consistent performance, archive data, or custom configurations. OnFinality provides dedicated Solana nodes that you can spin up in minutes. See RPC pricing and supported networks for details.
If you are unsure, start with the public endpoint for development, then move to a dedicated node before mainnet launch.
Solana JSON-RPC Methods You Will Actually Use
Solana's RPC has dozens of methods, but you will likely use a small subset. Here are the most common ones grouped by purpose.
Account and State Queries
getBalance– returns the SOL balance of a public key.getAccountInfo– returns the account's data, lamports, owner, and executable flag.getTokenAccountsByOwner– lists token accounts owned by a wallet.getProgramAccounts– fetches all accounts owned by a program (used heavily for indexing).
Transaction and Block Data
getTransaction– retrieves a transaction by signature, with optional parsed JSON.getBlock– returns a block's transactions and metadata.getLatestBlockhash– gets the current blockhash, which you need to sign transactions.sendTransaction– submits a signed transaction to the cluster.
Network and Cluster Info
getVersion– returns the node's software version.getSlot– gets the current slot number.getEpochInfo– returns epoch and slot details.
WebSocket Subscriptions
accountSubscribe– notifies when an account's data changes.logsSubscribe– streams logs for a program or transaction.slotSubscribe– notifies on new slots.
Connecting to a Solana RPC Endpoint
You can call Solana JSON-RPC with any HTTP client. Here is a basic curl example that gets 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",
"params": []
}'
Response:
{
"jsonrpc": "2.0",
"result": {
"context": {
"slot": 123456789
},
"value": {
"blockhash": "5xYk...",
"lastValidBlockHeight": 123456789
}
},
"id": 1
}
For JavaScript, you can use the official @solana/web3.js library, which wraps the RPC calls. Here is how to connect and fetch a balance:
import { Connection, PublicKey } from '@solana/web3.js';
const connection = new Connection('https://solana.api.onfinality.io/public');
const publicKey = new PublicKey('YourPublicKeyHere');
const balance = await connection.getBalance(publicKey);
console.log('Balance in lamports:', balance);
For WebSocket subscriptions, you can use the Connection object's subscription methods:
const subscriptionId = connection.onAccountChange(publicKey, (accountInfo) => {
console.log('Account updated:', accountInfo);
});
Common JSON-RPC Errors and How to Fix Them
Solana RPC errors can be cryptic. Here are the most frequent ones and what they mean.
| Error | Cause | Fix |
|---|---|---|
-32002: Transaction simulation failed | The transaction would fail if executed | Check logs, simulate with preflightCommitment |
-32003: Transaction precompile verification failure | Invalid program or instruction | Verify program IDs and instruction data |
-32004: Transaction signature verification failure | Signature is invalid | Ensure you signed with the correct keypair |
-32005: Blockhash not found | Blockhash expired or invalid | Fetch a fresh blockhash and retry |
-32007: Transaction expired | Transaction was not confirmed in time | Increase maxRetries or use a newer blockhash |
-32602: Invalid params | Parameters are malformed | Check the method's expected parameter types |
Debugging Tips
- Always simulate first: Use
simulateTransactionbefore sending to catch errors without spending fees. - Check commitment levels: Use
confirmedorfinalizedfor critical operations. - Use the explorer: Paste the transaction signature into Solana Explorer to see detailed logs.
- Enable logs: For program errors, subscribe to logs or use
getTransactionwithencoding: "jsonParsed".
Production Readiness Checklist for Solana RPC
When you move to production, verify these points to avoid downtime.
- Use a dedicated endpoint – public endpoints are not reliable for production.
- Set up failover – have a backup endpoint in case the primary fails.
- Monitor rate limits – track your usage and plan for spikes.
- Handle WebSocket reconnects – implement automatic reconnection logic.
- Use
getLatestBlockhashwith retries – blockhash expires quickly. - Choose the right commitment –
confirmedis a good default for most apps. - Archive data? – if you need historical state, ensure your provider supports archive nodes.
Key Takeaways
- Solana JSON-RPC is the standard API for reading and writing data on Solana.
- Public endpoints are fine for development, but production apps should use dedicated nodes.
- Learn the core methods:
getBalance,getAccountInfo,sendTransaction, andgetLatestBlockhash. - Use WebSocket subscriptions for real-time updates.
- Debug common errors by simulating transactions and checking commitment levels.
Frequently Asked Questions
What is the difference between JSON-RPC and gRPC on Solana?
JSON-RPC is the standard HTTP/WebSocket API, while gRPC is a newer, more efficient protocol used for streaming data. Most applications use JSON-RPC; gRPC is for high-throughput indexers.
How do I get a Solana RPC endpoint?
You can use a public endpoint like https://solana.api.onfinality.io/public or create a dedicated node through a provider like OnFinality. See Solana network page for options.
What is the best commitment level to use?
For most use cases, confirmed is a good balance between speed and reliability. Use finalized only when you need absolute certainty.
Can I use WebSocket with Solana RPC?
Yes, Solana supports WebSocket subscriptions for real-time updates. Use the wss:// endpoint and methods like accountSubscribe.
How do I handle rate limits on public endpoints?
Public endpoints have limits. For production, use a dedicated node or a provider that offers higher limits. OnFinality's RPC pricing page has details.
What is a blockhash and why does it expire?
A blockhash is a recent hash that prevents replay attacks. It expires after a few slots, so you must fetch a fresh one before each transaction.
How do I debug a failed transaction?
Use simulateTransaction to see errors without sending. Also check the transaction logs via the explorer or getTransaction with encoding: "jsonParsed".
What is getProgramAccounts and why is it slow?
getProgramAccounts returns all accounts owned by a program. It can be slow and resource-intensive, so use it sparingly and consider indexing alternatives.
How do I choose between a shared and dedicated node?
Shared nodes are cheaper but have rate limits. Dedicated nodes offer better performance and isolation. Evaluate your traffic and reliability needs.
Where can I find Solana RPC documentation?
The official Solana docs are a good start. For provider-specific details, check OnFinality's Solana network page.