Configure Horizon API endpoints for Stellar to connect to different networks, use custom nodes, or optimize performance. Stellar uses Horizon as its HTTP API layer instead of traditional RPC endpoints.
Configure Horizon Server
import { Horizon, Networks } from "@stellar/stellar-sdk";// Public Horizon endpointsconst mainnetServer = new Horizon.Server("https://horizon.stellar.org");const testnetServer = new Horizon.Server("https://horizon-testnet.stellar.org");// Custom Horizon endpoint (e.g., self-hosted or third-party provider)const customServer = new Horizon.Server("https://your-custom-horizon.example.com", { allowHttp: false, // set to true only for local development});
Switch Networks
When switching between mainnet and testnet, update both the Horizon URL and the network passphrase used for signing: