Skip to main content
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 endpoints
const 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:
import { useStellarSigner } from "@getpara/react-sdk/stellar";
import { Horizon, Networks } from "@stellar/stellar-sdk";

type StellarNetwork = "mainnet" | "testnet";

const NETWORK_CONFIG = {
  mainnet: {
    horizonUrl: "https://horizon.stellar.org",
    networkPassphrase: Networks.PUBLIC,
  },
  testnet: {
    horizonUrl: "https://horizon-testnet.stellar.org",
    networkPassphrase: Networks.TESTNET,
  },
} as const;

function useStellarNetwork(network: StellarNetwork) {
  const config = NETWORK_CONFIG[network];

  const { stellarSigner, isLoading } = useStellarSigner({
    networkPassphrase: config.networkPassphrase,
  });

  const server = new Horizon.Server(config.horizonUrl);

  return { server, signer: stellarSigner, isLoading, networkPassphrase: config.networkPassphrase };
}

Check Server Health

import { Horizon } from "@stellar/stellar-sdk";

async function checkHorizonHealth() {
  const server = new Horizon.Server("https://horizon.stellar.org");

  // Get ledger info
  const ledger = await server.ledgers().order("desc").limit(1).call();
  const latestLedger = ledger.records[0];
  console.log("Latest ledger:", latestLedger.sequence);
  console.log("Closed at:", latestLedger.closed_at);

  // Get fee stats
  const feeStats = await server.feeStats();
  console.log("Base fee:", feeStats.last_ledger_base_fee);
  console.log("Fee charged (p50):", feeStats.fee_charged.p50);
}

Next Steps