Status: implemented. The
stellar-router-sdknpm package ships theRouterClientclass and the API described below. It is not yet published to the npm registry; to use it from this repository,npm installinsidesdk/or link the package into your own project.
A client library for interacting with the stellar-router contracts from JS/TS.
npm install stellar-router-sdkimport { RouterClient } from "stellar-router-sdk";
import { Keypair } from "@stellar/stellar-sdk";
const client = new RouterClient({
network: "testnet",
coreContractId: "C...",
quoteContractId: "C...", // optional — enables quote methods
keypair: Keypair.fromSecret("S..."), // optional — enables admin writes
});
const address = await client.resolve("oracle");
await client.registerRoute("oracle", "C...", { description: "Price feed" });resolve(name)→Promise<string>batchResolve(names)→Promise<BatchResolveResult[]>registerRoute(name, address, metadata?)→Promise<void>registerRoutesBatch(routes)→Promise<void>updateRoute(name, newAddress)→Promise<void>removeRoute(name)→Promise<void>removeRoutesBatch(names)→Promise<void>setRoutePaused(name, paused)→Promise<void>setPaused(paused)→Promise<void>getRoute(name)→Promise<RouteEntry | null>getMetadata(name)→Promise<RouteMetadata | null>totalRouted()→Promise<bigint>routeCount()→Promise<number>getBestRoute(candidates, minScore, fallbackName?)→Promise<string | null>getRouteScore(name)→Promise<RouteScore | null>getAliasTarget(aliasName)→Promise<string | null>
getQuote(request)→Promise<QuoteResponse>getQuotes(requests)→Promise<QuoteResponse[]>getBestQuote(requests)→Promise<QuoteResponse>compareQuotes(requests, maxPriceImpactBps)→Promise<QuoteResponse[]>getRouteFee(route)→Promise<number>getDefaultFee()→Promise<number>
The underlying sub-clients are exposed as client.core and client.quote
for lower-level access, including admin fee management (setRouteFee,
setDefaultFee).
All methods throw RouterSdkError with a .code on failure, e.g.
"RouteNotFound", "RoutePaused", "RouterPaused", "NoSigner",
"InvalidRouteName", "InvalidContractId", or
"QuoteContractNotConfigured". On-chain contract errors are mapped to their
SDK names; a raw Error(Contract, #N) is parsed and surfaced with
err.contractErrorCode and err.code set accordingly.
State-changing calls require an authenticated account. Pass either a
keypair (in-memory signing) or a signer implementing the Signer
interface (publicKey() and sign(tx)). LocalSigner and FreighterSigner
are provided — see signing-abstraction.md.
The release process for the package. Not run automatically.
cd sdk
npm version patch
npm publish