Blog

Developer Guide

Horizon API vs Stellar RPC: Which One Should Your App Use?

If you are building on Stellar, you have two primary ways to interact with the network: the Horizon API and the Stellar RPC (formerly Soroban RPC). They serve different purposes, and most production applications end up using both. Here is when to use each.

What Horizon Does

Horizon is a RESTful API server that ingests the Stellar ledger and provides indexed, queryable access to historical and current blockchain data. Think of it as a read-optimized database layer on top of the raw ledger.

Horizon's Strengths

  • Historical data: Horizon indexes every transaction, operation, effect, and payment that has ever occurred on the network
  • Rich querying: Filter by account, asset, operation type, time range, and more with cursor-based pagination
  • Account state: Fetch balances, signers, thresholds, offers, trustlines in a single call
  • Asset discovery: List all assets, filter by code or issuer, see holder counts and supply
  • Key Horizon Endpoints

    EndpointPurpose
    `/accounts/{id}`Account balances, signers, thresholds
    `/transactions`Transaction history with filtering
    `/operations`Operation details across all types
    `/payments`Payment-specific operations
    `/assets`Asset listing with holder counts
    `/order_book`Current order book for any pair
    `/trade_aggregations`OHLCV candle data
    `/fee_stats`Current network fee statistics
    `/ledgers`Ledger history with metadata

    When to Use Horizon

  • Displaying account balances and transaction history
  • Building block explorers or portfolio trackers
  • Querying historical payment data
  • Showing order books and trading activity
  • Fetching network statistics (TPS, fees, ledger data)
  • What Stellar RPC Does

    Stellar RPC is a JSON-RPC interface for interacting with the network's current state and smart contracts. It was originally called Soroban RPC and now serves as the unified real-time interface.

    RPC's Strengths

  • Transaction simulation: Dry-run transactions to see results, resource costs, and fees before submitting
  • Real-time state: Current ledger state without indexing delay
  • Smart contract interaction: Query contract storage, invoke functions, monitor events
  • Event streaming: Query contract events by topic, contract ID, or ledger range
  • Key RPC Methods

    MethodPurpose
    `getLatestLedger`Current ledger sequence and protocol version
    `simulateTransaction`Dry-run a transaction, get resource estimates
    `sendTransaction`Submit a signed transaction
    `getTransaction`Check transaction status by hash
    `getEvents`Query contract events with filters
    `getLedgerEntries`Read specific ledger entries

    When to Use RPC

  • Submitting transactions (especially Soroban)
  • Simulating transactions before submission
  • Reading smart contract storage state
  • Monitoring contract events
  • Building DeFi or smart contract applications
  • Side-by-Side Comparison

    CapabilityHorizonStellar RPC
    **Protocol**REST (HTTP)JSON-RPC
    **Historical data**Yes (full history)No (recent only)
    **Transaction submission**Yes (basic)Yes (with simulation)
    **Smart contract storage**NoYes
    **Contract events**NoYes
    **Transaction simulation**NoYes
    **Order book**YesNo
    **Trade aggregations**YesNo
    **Asset listing**YesNo

    Using Both Together

    Most production applications use both:

  • Horizon for reads: Account balances, transaction history, asset discovery, analytics
  • RPC for writes: Transaction simulation, submission, and status polling
  • RPC for contracts: Storage reads, event monitoring, function invocation
  • Example: Building a token dashboard — use Horizon for asset info, holder counts, payment history. Use RPC for reading DeFi contract state and monitoring events.

    Infrastructure Considerations

    Running your own Horizon instance requires PostgreSQL, Captive Core, disk management, and 24/7 monitoring. Running RPC is simpler but still needs infrastructure. Managed services like LumenQuery handle all of this:

  • [Horizon API](/docs): Full indexed access with caching and rate limiting
  • [Soroban RPC](/docs/contracts): Contract interaction and transaction submission
  • [Network Analytics](/analytics): Pre-built dashboards for network metrics

  • *Build on both APIs without running a single node. LumenQuery provides managed Horizon and Soroban RPC with sub-100ms response times. Start free.*