Set up and configure Stellar Horizon API endpoints for different networks
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
});
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 };
}
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);
}