Skip to main content

Migrate from Horizon to RPC

Applications using Horizon's REST-like API will need to be updated to use the RPC JSON-RPC API when migrating from Horizon to RPC. This guide provides an overview of the key differences between the two APIs and how to migrate your application.

Request / Response Format

Horizon's REST-like API uses HTTP methods and status codes to communicate with clients. Responses are JSON in the HAL format. See Horizon's Response Format.

RPC's JSON-RPC API uses JSON-RPC 2.0 to communicate with clients. Requests to the API are JSON objects that contain one or more method invocations. Responses are also JSON objects that contain a result for each invocation in the request. See JSON-RPC.

Both formats utilise JSON for the overall structure which are relatively simple and do not require any special client code, although there are client SDKs available. Some values contained within are XDR encoded and can be decoded using Stellar SDKs.

Endpoint Mapping

Applications that use the following Horizon endpoints can typically migrate directly to the RPC using the referenced methods.

Endpoints without mappings do not have a direct replacement in the RPC API. To build similar functionality in an application, please consider partnering with an indexer or using the information listed below to build your own indexed representation of horizon endpoints. Consider using other Data products for analytics use cases.

Horizon EndpointCorresponding RPC Method(s)Indexer EquivalentAnalytics Resources
GET /getLatestLedger getVersionInfo getHealth getNetworkNot applicableAnalyst Guide
GET /ledgersgetLedgersCreate a getLedgers with full history, using Galexie, to build a historical ledger view.Ledgers
GET /ledgers/{seq}getLedgers (with filter for sequence)Use a getLedgers view with full history, filtered by ledger sequenceLedgers
GET /ledgers/{seq}/transactionsgetTransactions (with filter for ledger sequence)Use getTransactions with ledger sequence filtering to retrieve transactions for a specific ledgerTransactions
GET /ledgers/{seq}/operationsgetTransactionsUse getTransactions for the given ledger, then parse the transaction's XDR for individual operations.Operations
GET /ledgers/{seq}/paymentsgetEvents getTransactions ⚠️Use getEvents (specifically CAP-67 events when available) and parse getTransactions meta XDR to identify payment-like operations.Payments
GET /ledgers/{seq}/effectsgetEvents getTransactions ⚠️Use getEvents (when expanded to cover all effects with CAP-67) and parse getTransactions meta XDR for relevant data.Effects
POST /transactionssendTransactionNot applicableNot applicable
POST /transactions_asyncsendTransactionNot applicableNot applicable
GET /transactionsgetTransactionsUse getTransactions to build a historical transaction listTransactions
GET /transactions/{hash}getTransactionUse getTransaction to retrieve a specific transaction by its hashTransactions
GET /transactions/{hash}/operationsgetTransactionFilter getTransaction by hash and then parse its XDR for operationsOperations
GET /transactions/{hash}/paymentsNo direct RPC equivalent; use getEvents or parse getTransactionsFilter getTransaction by hash and analyze its events and operation types to identify payments.Payments
GET /transactions/{hash}/effectsNo direct RPC equivalent; use getEvents or parse getTransactionsFilter getTransaction by hash and analyze its events and metadata for relevant data.Effects
GET /operationsgetTransactionsIngest all historical ledgers/transactions and build and build a view of operations for filtering.Operations
GET /operations/{id}No direct RPC equivalentStore Horizon's operation ID and map it back to the ledger sequence and transaction index to retrieve the relevant transaction via getTransactions.Operations
GET /operations/{id}/effectsNo direct RPC equivalentRetrieve the operation by ID (as above) and then parse its associated transaction and events for effects.Effects
GET /fee_statsgetFeeStats simulateTransactionIndexed data not recommended.Fee Stats
GET /accountsNo direct RPC equivalentIngest all ledger history via getLedgers to build and maintain a complete list of accounts.Accounts
GET /accounts/{address}getLedgerEntriesUse getLedgerEntries for a specific account address. Note: RPC will not provide trust line information associated with the account directly, as Horizon does. You will need to derive this from ledger entries.Accounts
GET /claimable_balancesNo direct RPC equivalentIngest all ledger history via getLedgers to build and maintain a complete list of claimable balances.Claimable Balances
GET /claimable_balances/{id}getLedgerEntriesUse getLedgerEntries to retrieve a specific claimable balance by ID.Claimable Balances
GET /claimable_balances/{id}/transactionsNo direct RPC equivalentTrace transactions that interact with the specific claimable balance ID from their historical ledger data.Claimable Balances
GET /claimable_balances/{id}/operationsNo direct RPC equivalenttrace operations related to the specific claimable balance ID from your historical ledger data.Claimable Balances
GET /liquidity_poolsNo direct RPC equivalentingest all ledger history via getLedgers to build and maintain a complete list of liquidity pools.Liquiditity Pools
GET /liquidity_pools/{id}getLedgerEntriesUse getLedgerEntries to retrieve a specific liquidity pool by ID.Liquiditity Pools
GET /liquidity_pools/{id}/transactionsNo direct RPC equivalentTrace transactions that interact with the specific liquidity pool ID from their historical ledger data.Liquiditity Pools
GET /liquidity_pools/{id}/operationsNo direct RPC equivalentTrace operations related to the specific liquidity pool ID from their historical ledger data.Liquiditity Pools
GET /liquidity_pools/{id}/effectsNo direct RPC equivalentTrace effects related to the specific liquidity pool ID from their historical ledger data.Liquiditity Pools
GET /liquidity_pools/{id}/tradesNo direct RPC equivalentInfer trades related to the specific liquidity pool ID from historical ledger data (e.g., from getEvents and getTransactions metadata).Liquiditity Pools
GET /offersNo direct RPC equivalentIngest all ledger history via getLedgers to build and maintain a complete list of offers.Offers
GET /offers/{id}getLedgerEntriesUse getLedgerEntries to retrieve a specific offer by ID.Offers
GET /offers/{id}/tradesNo direct RPC equivalentInfer trades related to the specific offer ID from historical ledger data (e.g., from getEvents and getTransactions metadata).Offers
GET /paymentsgetEvents getTransactions ⚠️Use getEvents (CAP-67 events) and process getTransactions metadata for payment-like operations across all history.Payments
GET /effectsgetEvents getTransactions ⚠️Use getEvents (when expanded) and process getTransactions metadata to derive effects across all history.Effects
GET /tradesgetEvents getTransactions ⚠️Infer trades from getEvents and getTransactions metadata across all history, as there is no direct "trade event" in RPC.Trades
tip

The getTransactions method can be used to retrieve events batched by transaction. The events are contained in the meta XDR of the transaction (field resultMetaXdr).

warning

The getEvents method is not a direct replacement for Horizon's endpoints.

The method returns a stream of events that in the current protocol only include events from contracts. In the near future as a result of CAP-67 this method will be expanded to include events from non-contract operations.

In the interim the getTransactions method can be used to retrieve the meta XDR of transactions containing non-contract operations to determine what movements of value have occurred. The meta XDR also contains events from contracts.