DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

Solana RPC Endpoint: Setup, Config & Debugging

Quick decision guide: which Solana RPC endpoint should you use?

Before diving into configuration, decide which endpoint type fits your use case:

  • Public RPC endpoints (like https://solana.api.onfinality.io/public) are free and fine for development, testing, and low-traffic apps. They are rate-limited and shared, so they are not suitable for production workloads.
  • Managed RPC endpoints from a provider like OnFinality offer higher rate limits, WebSocket support, and reliability for production dApps. They are a good middle ground for most projects.
  • Dedicated Solana nodes give you a private, isolated endpoint with no sharing and full control. Choose this for high-throughput applications, validators, or when you need consistent performance.

If you are building a production app, skip the public endpoint and go straight to a managed or dedicated solution. Check RPC pricing and supported networks to see your options.

What is a Solana RPC endpoint?

A Solana RPC endpoint is a URL that accepts JSON-RPC requests over HTTP or WebSocket. It acts as the gateway between your application and the Solana blockchain. Every transaction, account query, and program invocation goes through an RPC endpoint.

Solana's RPC API is based on JSON-RPC 2.0. You send a POST request with a method and parameters, and the endpoint returns a result or error. WebSocket endpoints allow you to subscribe to account changes, program logs, and transaction confirmations.

Solana mainnet and devnet endpoints

Solana has several clusters. The two most common are mainnet-beta (production) and devnet (development). Here are the official public endpoints from OnFinality:

Cluster HTTP Endpoint WebSocket Endpoint
Mainnet https://solana.api.onfinality.io/public wss://solana.api.onfinality.io/public-ws
Devnet See Solana Devnet See Solana Devnet

Note: Public endpoints are rate-limited and shared. For production, use a managed or dedicated endpoint from OnFinality.

How to connect to a Solana RPC endpoint

You can interact with a Solana RPC endpoint using curl, JavaScript libraries like @solana/web3.js, or any HTTP client. Here's a basic curl example 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"}'
Enter fullscreen mode Exit fullscreen mode

The response will look like:

{
  "jsonrpc": "2.0",
  "result": {
    "blockhash": "5xYk...",
    "lastValidBlockHeight": 123456
  },
  "id": 1
}
Enter fullscreen mode Exit fullscreen mode

Using @solana/web3.js

For JavaScript dApps, the @solana/web3.js library is the standard. Configure the connection with your endpoint:

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://solana.api.onfinality.io/public', 'confirmed');

// Fetch the latest blockhash
const { blockhash } = await connection.getLatestBlockhash();
console.log(blockhash);
Enter fullscreen mode Exit fullscreen mode

For WebSocket subscriptions, use the WebSocket URL:

import { Connection } from '@solana/web3.js';

const wsEndpoint = 'wss://solana.api.onfinality.io/public-ws';
const connection = new Connection(wsEndpoint, 'confirmed');

// Subscribe to account changes
const subscriptionId = connection.onAccountChange(
  somePublicKey,
  (accountInfo) => console.log(accountInfo)
);
Enter fullscreen mode Exit fullscreen mode

Common Solana RPC methods

Solana's RPC API includes many methods. Here are the most frequently used:

  • getBalance – get the SOL balance of an account.
  • getLatestBlockhash – get the current blockhash for transaction signing.
  • sendTransaction – submit a signed transaction.
  • getTransaction – fetch transaction details.
  • getAccountInfo – retrieve account data.
  • getProgramAccounts – get all accounts owned by a program.
  • getSlot – get the current slot.
  • getBlock – get block information.
  • getSignaturesForAddress – list transaction signatures for an address.
  • onAccountChange (WebSocket) – subscribe to account updates.
  • onLogs (WebSocket) – subscribe to program logs.

For a complete list, see the Solana documentation.

Debugging Solana RPC connection issues

If you're having trouble connecting, here are common symptoms and fixes:

Symptom Possible Cause Fix
429 Too Many Requests Rate limit exceeded Use a managed or dedicated endpoint, or reduce request frequency.
403 Forbidden IP blocked or unauthorized Check your API key or use a public endpoint.
Timeout Network issue or overloaded endpoint Retry with backoff, or switch to a more reliable provider.
Invalid params Malformed JSON-RPC request Validate your request structure.
WebSocket disconnects Unstable connection Implement reconnection logic.
Blockhash not found Transaction too old Fetch a new blockhash and resubmit.

Quick test with curl

To verify your endpoint is reachable, run:

curl https://solana.api.onfinality.io/public -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"getHealth"}'
Enter fullscreen mode Exit fullscreen mode

A healthy node returns {"result":"ok"}.

Production considerations for Solana RPC

When moving to production, consider the following:

  • Rate limits: Public endpoints have strict limits. Managed endpoints offer higher throughput.
  • WebSocket stability: For real-time features, ensure your provider supports WebSocket and handles reconnections.
  • Geographic latency: Choose an endpoint close to your users to reduce latency.
  • Archive data: If you need historical state, you may need an archive node.
  • Failover: Implement multiple endpoints and failover logic to avoid downtime.

OnFinality provides dedicated Solana nodes and managed RPC services that address these concerns.

Key Takeaways

  • A Solana RPC endpoint is the URL for JSON-RPC requests to the Solana network.
  • Use public endpoints for development, but switch to managed or dedicated for production.
  • Configure your connection with the correct HTTP or WebSocket URL.
  • Debug common issues by checking rate limits, request format, and network stability.
  • For production, evaluate providers based on rate limits, WebSocket support, and reliability.

Frequently Asked Questions

What is the Solana RPC endpoint URL?

The public mainnet endpoint is https://solana.api.onfinality.io/public. For WebSocket, use wss://solana.api.onfinality.io/public-ws. For devnet, see Solana Devnet.

How do I get a Solana RPC endpoint?

You can use a public endpoint for free, or sign up for a managed RPC service like OnFinality to get a dedicated endpoint with higher limits.

What is the difference between HTTP and WebSocket RPC endpoints?

HTTP is for request-response calls, while WebSocket allows real-time subscriptions. Use WebSocket for features like live account updates.

Can I use a Solana RPC endpoint for free?

Yes, public endpoints are free but rate-limited. For production, consider a paid plan.

How do I choose a Solana RPC provider?

Evaluate providers based on rate limits, WebSocket support, uptime, and pricing. See our Solana RPC provider comparison for guidance.

Related resources

Originally published at OnFinality.

Top comments (0)