Logo

What is Stellar RPC and how do you use it?

Key Takeaways

  • Stellar RPC is primarily accessed via the Horizon REST API and the Soroban RPC for smart contracts.
  • Horizon endpoints allow querying accounts, transactions, offers, and ledger data.
  • Soroban RPC enables contract deployment, invocation, and event retrieval using JSON-RPC.
  • Authentication for public Stellar RPC endpoints is typically not required, but rate limits apply.
  • For production applications, use a managed RPC provider like OnFinality to ensure reliability and scalability.
  • Stellar testnet is available for development and can be accessed via dedicated testnet RPC endpoints.
  • Choosing between shared and dedicated RPC nodes depends on your throughput and latency requirements.

Understanding Stellar RPC: Horizon vs Soroban

Stellar offers two primary RPC interfaces: Horizon and Soroban RPC. Horizon is a RESTful API that provides access to core Stellar network data such as accounts, transactions, and ledger entries. It is the most common way to interact with Stellar for traditional payment and asset operations.

Soroban RPC is a JSON-RPC interface introduced for Stellar's smart contract platform. It allows developers to deploy and invoke contracts, query contract state, and subscribe to contract events. Soroban RPC follows the Ethereum JSON-RPC specification closely but uses Stellar-specific methods.

Both interfaces are essential for building on Stellar. OnFinality supports both Horizon and Soroban RPC endpoints, ensuring you have a single provider for all your Stellar development needs.

  • Horizon: RESTful API for accounts, transactions, offers, and ledger data.
  • Soroban RPC: JSON-RPC for smart contract deployment and invocation.
  • Both are available on mainnet and testnet.

Key Horizon Endpoints

Horizon provides a wide range of endpoints for interacting with the Stellar network. Below are some of the most commonly used ones.

CriterionWhat to checkWhy it matters
EndpointGET /accounts/{account_id}Retrieve account details, balances, and sequence number.
EndpointGET /transactions/{hash}Get transaction details including fee, memo, and operations.
EndpointPOST /transactionsSubmit a signed transaction to the network.
EndpointGET /ledgers/{sequence}Query ledger header and metadata.
EndpointGET /offers/{offer_id}Retrieve details of a specific offer on the decentralized exchange.

Soroban RPC Methods

Soroban RPC exposes methods similar to Ethereum's JSON-RPC. Key methods include:

  • getHealth: Check if the RPC node is synced and healthy.
  • getLedgerEntry: Retrieve a specific ledger entry (contract code, contract data, etc.).
  • sendTransaction: Submit a signed Soroban transaction.
  • getTransaction: Get the status and result of a submitted transaction.
  • simulateTransaction: Simulate a contract invocation to estimate fees and validate.
  • getEvents: Query contract events by topic or contract ID.

Authentication and Rate Limits

Public Stellar RPC endpoints (both Horizon and Soroban) typically do not require authentication. However, they enforce rate limits to prevent abuse. For example, the Stellar Development Foundation's public Horizon instance allows up to 10 requests per second per IP. Soroban RPC endpoints may have similar or stricter limits.

For production applications, relying on public endpoints is risky due to potential throttling or downtime. Using a managed RPC provider like OnFinality gives you higher rate limits, dedicated throughput, and SLA-backed availability. OnFinality also offers API keys for authentication and usage tracking.

Choosing Between Shared and Dedicated Stellar RPC

Shared RPC endpoints are cost-effective and suitable for development, testing, and low-traffic applications. They pool resources across multiple users, which can lead to variable performance during peak usage.

Dedicated Stellar nodes provide isolated infrastructure with guaranteed performance, no rate limits, and full control over the node configuration. They are ideal for high-throughput applications, exchanges, or services that require consistent low latency.

OnFinality offers both shared and dedicated Stellar RPC options. You can start with a shared endpoint and upgrade to dedicated as your application grows.

Best Practices for Stellar RPC Integration

When integrating Stellar RPC, follow these best practices to ensure reliability and efficiency.

  • Use connection pooling and retry logic to handle transient failures.
  • Monitor your rate limit usage and upgrade to a dedicated node if you consistently hit limits.
  • Cache frequently accessed data (e.g., account details) to reduce RPC calls.
  • For Soroban, always simulate transactions before submission to catch errors and estimate fees.
  • Use testnet for development and staging before deploying to mainnet.
  • Choose a provider with global edge caching to minimize latency.

Getting Started with OnFinality Stellar RPC

OnFinality provides managed Stellar RPC endpoints for both Horizon and Soroban. To get started:

1. Sign up for an OnFinality account and navigate to the Stellar network page. 2. Obtain your API endpoint URL and optional API key. 3. Configure your application to use the endpoint, setting appropriate headers for authentication if required. 4. Start making requests using your preferred HTTP client or SDK. OnFinality endpoints are optimized for low latency and high availability, with automatic failover and load balancing.

  • Instant access to Stellar mainnet and testnet RPC.
  • Supports both Horizon REST and Soroban JSON-RPC.
  • Scalable from shared to dedicated nodes.
  • 24/7 monitoring and support.

Frequently Asked Questions

What is the difference between Horizon and Soroban RPC?

Horizon is a RESTful API for core Stellar network operations (accounts, transactions, offers). Soroban RPC is a JSON-RPC interface for smart contract interactions on the Soroban platform.

Do I need an API key to use Stellar RPC?

Public Stellar RPC endpoints typically do not require an API key, but they have rate limits. Managed providers like OnFinality may offer API keys for higher limits and usage tracking.

Can I use Stellar RPC for Soroban smart contracts?

Yes, Soroban RPC is specifically designed for deploying and invoking smart contracts on Stellar. It provides methods like sendTransaction, simulateTransaction, and getEvents.

What are the rate limits for Stellar RPC?

Public endpoints often limit to 10 requests per second per IP. Managed providers offer higher limits or unlimited access with dedicated nodes.

How do I choose between shared and dedicated Stellar RPC?

Shared RPC is suitable for development and low-traffic apps. Dedicated RPC is recommended for production applications with high throughput or low latency requirements.

stellar rpc
RPC Knowledge Base

Related RPC details

Background

Never Worry about Infrastructure Again

OnFinality takes away the heavy lifting of DevOps so you can build smarter and faster.

Get Started