DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

Solana API Endpoint: How to Choose the Right One

Quick recommendation: which Solana endpoint should you use?

If you are prototyping or building on Devnet, a public endpoint is fine for short bursts of activity. For production Mainnet traffic, you need a managed RPC provider with a dedicated or high-throughput shared endpoint. The right choice depends on your request volume, latency requirements, and whether you need WebSocket subscriptions.

  • Development and testing: Use a public Devnet endpoint or a free tier from a provider like OnFinality. You can get started without a credit card.
  • Production applications: Use a managed RPC service with a dedicated node or a high-throughput shared endpoint. This gives you consistent performance and support.
  • High-frequency trading or analytics: A dedicated Solana node is often the best fit because it isolates your traffic and allows you to tune the node for your workload.

For most teams, starting with a managed shared endpoint and upgrading to a dedicated node as traffic grows is the most cost-effective path. OnFinality offers both options, and you can compare pricing on the RPC pricing page.

What is a Solana API endpoint?

A Solana API endpoint is a URL that your application uses to send JSON-RPC requests to the Solana blockchain. These requests can query account balances, fetch transaction details, submit transactions, and subscribe to real-time events. The endpoint is the gateway between your app and the Solana network.

Solana's RPC API is a JSON-over-HTTP and WebSocket interface. Most requests are simple POST requests with a JSON body, while WebSocket connections allow you to subscribe to account changes, program logs, and other events.

Solana clusters and their endpoints

Solana operates several clusters, each with its own purpose and public endpoints. The main ones are:

  • Mainnet: The live production network where real SOL and programs run.
  • Devnet: A developer playground where you can test programs and get free SOL from a faucet.
  • Testnet: A staging environment for stress-testing network upgrades and validator performance.

Each cluster has a public endpoint operated by Solana Labs, but these are rate-limited and not suitable for production. For reliable access, you should use a managed RPC provider.

Cluster Purpose Public Endpoint Notes
Mainnet Production https://api.mainnet.solana.com Requires SOL for transactions
Devnet Development https://api.devnet.solana.com Free SOL from faucet
Testnet Stress testing https://api.testnet.solana.com Not for production

How to connect to a Solana endpoint

Connecting to a Solana endpoint is straightforward. You can use the official Solana Web3.js library or any HTTP client that supports JSON-RPC.

Here is a basic example using @solana/web3.js:

import { Connection, clusterApiUrl } from "@solana/web3.js";

// Use a public endpoint for development
const connection = new Connection(clusterApiUrl("devnet"));

// Or use a custom endpoint
const customConnection = new Connection("https://solana.api.onfinality.io/public");

// Check the connection
const version = await customConnection.getVersion();
console.log(version);
Enter fullscreen mode Exit fullscreen mode

For a raw JSON-RPC request, you can use curl:

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

Public vs. shared vs. dedicated endpoints

Understanding the difference between endpoint types is key to choosing the right one.

  • Public endpoints: Operated by Solana Labs or community members. They are free but heavily rate-limited and often unreliable for production. They are fine for occasional testing.
  • Shared endpoints: Provided by RPC services like OnFinality. Multiple users share the same infrastructure, but the provider manages capacity and load balancing. These are suitable for most production apps with moderate traffic.
  • Dedicated endpoints: You get a dedicated Solana node (or a cluster of nodes) that is not shared with other users. This offers the highest performance and reliability, and is ideal for high-throughput applications, trading bots, or analytics platforms.
Endpoint Type Cost Performance Use Case
Public Free Low Testing, small scripts
Shared Subscription Medium Production apps with moderate traffic
Dedicated Higher High High-frequency trading, large-scale analytics

How to evaluate a Solana RPC provider

When choosing a provider, consider these factors:

  • Request limits: What is the maximum requests per second (RPS) or monthly request allowance? Does the provider enforce fair use policies?
  • WebSocket support: Does the provider offer WebSocket endpoints for real-time subscriptions? This is critical for applications that need live updates.
  • Geographic distribution: Are the nodes located in multiple regions? This reduces latency for users around the world.
  • Archive data: Does the provider offer historical data access? This is important for analytics and backtesting.
  • Support and SLAs: What level of support is available? Are there uptime guarantees?

OnFinality provides Solana Mainnet and Devnet endpoints with HTTP and WebSocket support. You can find more details on the Solana network page and the Solana Devnet page.

Common pitfalls and troubleshooting

Even with a good endpoint, you may encounter issues. Here are some common problems and how to fix them:

  • Rate limiting (HTTP 429): You are sending too many requests. Reduce your request rate, implement caching, or upgrade to a higher-tier plan.
  • Connection timeouts: The endpoint is slow or unreachable. Check your network connection, try a different region, or use a dedicated node.
  • WebSocket disconnects: Your subscription may be dropped due to inactivity or network issues. Implement reconnection logic in your client.
  • Invalid API key: If you are using a managed provider, ensure your API key is correct and has the right permissions.

For a quick health check, you can call the getHealth method:

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

If the response is {"result":"ok"}, the endpoint is healthy.

Key Takeaways

  • A Solana API endpoint is the URL your app uses to interact with the Solana blockchain via JSON-RPC.
  • Public endpoints are fine for testing, but production apps need a managed provider with shared or dedicated endpoints.
  • Evaluate providers based on request limits, WebSocket support, geographic distribution, archive data, and support.
  • OnFinality offers Solana Mainnet and Devnet endpoints with HTTP and WebSocket support. Check the pricing page for details.

Frequently Asked Questions

What is the difference between a Solana RPC endpoint and an API endpoint?

They are essentially the same. An RPC endpoint is a type of API endpoint that uses the JSON-RPC protocol. In the Solana ecosystem, the terms are used interchangeably.

Can I use a public Solana endpoint for production?

It is not recommended. Public endpoints are rate-limited and can be unreliable. For production, use a managed provider with a shared or dedicated endpoint.

How do I get a Solana Devnet endpoint?

You can use the public Devnet endpoint https://api.devnet.solana.com or a managed provider like OnFinality. OnFinality offers a Devnet endpoint that you can find on the Solana Devnet page.

Does OnFinality support WebSocket for Solana?

Yes, OnFinality provides WebSocket endpoints for Solana Mainnet. You can find the WebSocket URL on the Solana network page.

How do I choose between a shared and a dedicated Solana endpoint?

If your application has moderate traffic and you want to minimize cost, a shared endpoint is sufficient. If you need high throughput, low latency, or have unpredictable traffic spikes, a dedicated node is better. OnFinality offers both options, and you can compare them on the pricing page.

Related resources

Originally published at OnFinality.

Top comments (0)