// Developers
TypeScript SDK
@routerx.exchange/sdk is a typed client for on-chain quotes and swaps, Cross via rx.cross, plus limit order and DCA. Swap quotes call RXRouter over eth_call; Cross history uses the Cross API.
Installation#
npm install @routerx.exchange/sdkTargets Node 18+. The package depends on viem internally for utilities; you pass an EIP-1193 provider (wallet or custom RPC wrapper) when sending transactions.
Creating a client#
Instantiate RouterX with a chainId. A provider is optional for read-only quotes; required for approve / swap / Cross execute.
import { RouterX } from '@routerx.exchange/sdk'
const rx = new RouterX({
chainId: 8453,
provider: window.ethereum, // optional for quote-only
// rpcUrls: ['https://…'], // optional HTTP RPC override
// crossApiUrl: 'https://cross-api.routerx.exchange',
})swap.quote()#
On-chain gas-adjusted quote via RXRouter findBestPathWithGas. Amounts are decimal strings in base units.
const quote = await rx.swap.quote({
tokenIn: '0x4200000000000000000000000000000000000006', // WETH on Base
tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
amountIn: '1000000000000000000',
// maxSteps?: number
// gasPrice?: string // wei
})
console.log(quote.amountOut)
console.log(quote.offer.path)
console.log(quote.router)| Option | Type | Description |
|---|---|---|
tokenIn | string | Input token. Required. Native: NATIVE_PLACEHOLDER. |
tokenOut | string | Output token. Required. |
amountIn | string | Input amount in base units. Required. |
maxSteps | number | Max hops. Optional. |
gasPrice | string | Wei for gas-aware scoring. Optional. |
swap.swap()#
Quotes, optionally approves the router, and sends the swap transaction. Returns the built result plus hash.
const result = await rx.swap.swap({
tokenIn: '0x4200000000000000000000000000000000000006',
tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
amountIn: '1000000000000000000',
to: account, // recipient
slippage: 0.5, // percent; default 0.5
autoApprove: true, // default true for ERC-20
// approvalMode: 'exact' | 'infinite'
})
console.log(result.hash)
console.log(result.minAmountOut)
console.log(result.tx)Provider required
swap, approve, and Cross execute need a wallet provider on the client.swap.buildSwapTx()#
Same as swap without sending — returns minAmountOut and tx: { to, data, value } for your own broadcaster or simulator.
const built = await rx.swap.buildSwapTx({
tokenIn: '0x4200000000000000000000000000000000000006',
tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
amountIn: '1000000000000000000',
to: account,
slippage: 0.5,
})
// eth_call / Tenderly / your bot against built.txcross#
rx.cross.quote composes source/dest swap legs locally (RXRouter) plus Circle Iris Fast+Forwarder fees. Transfer history uses https://cross-api.routerx.exchange (routerx-cross). HTTP POST /v1/quote on that host is disabled.
import { RouterX, NATIVE_PLACEHOLDER } from '@routerx.exchange/sdk'
const rx = new RouterX({
chainId: 8453,
provider: window.ethereum,
crossApiUrl: 'https://cross-api.routerx.exchange',
})
const quote = await rx.cross.quote({
srcChainId: 8453,
dstChainId: 42161,
tokenIn: NATIVE_PLACEHOLDER,
tokenOut: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
amountIn: '1000000000000000000',
slippageBps: 50,
})
const { burnTxHash } = await rx.cross.execute({
quote,
from: account,
provider: window.ethereum,
srcChainId: 8453,
dstChainId: 42161,
tokenInDecimals: 18,
tokenOutDecimals: 6,
slippage: 0.5,
onStatus: (status) => console.log(status),
})Types#
Core shapes from the SDK:
interface QuoteResult {
chainId: number
tokenIn: string
tokenOut: string
amountIn: string
amountOut: string
offer: FormattedOffer
router: string
cached: boolean
legs?: QuoteSplitLeg[]
}
interface FormattedOffer {
amounts: string[]
adapters: { address: string; name: string }[]
path: string[]
gasEstimate: string
extras: string[] // aligned with adapters; pass to hops[i].extra
}
interface QuoteSplitLeg {
split: number // bps of post-fee amount; last leg takes remainder
hops: Array<{ adapter: string; tokenOut: string; extra: string }>
amountOut: string
}
interface SwapResult extends QuoteResult {
minAmountOut: string
tx: { to: string; data: string; value: string }
}- Also:
rx.limitOrderandrx.dcaon LO-capable chains. - See the Integration guide for contract addresses and the API reference for raw HTTP quote/swap.