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, take a look at other Data products.
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
).
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.