// Developers
TypeScript SDK
@routerx/sdk is a typed client for quoting, simulating, and settling routes. It wraps the REST API and the Router contract behind one ergonomic surface built on viem.
Installation#
npm install @routerx/sdk viemThe SDK targets Node 18+ and modern bundlers. viem is a peer dependency you provide, so the SDK shares your existing client and account setup.
Creating a client#
Instantiate RouterX with a viem chain. Pass a custom transport if you run your own RPC — quoting will use it for on-chain reads.
import { RouterX } from '@routerx/sdk'
import { http } from 'viem'
import { mainnet } from 'viem/chains'
const rx = new RouterX({
chain: mainnet,
transport: http(process.env.RPC_URL), // optional
})quote()#
Requests the best gas-adjusted route for a swap. Returns a typed, executable quote.
const quote = await rx.quote({
tokenIn: WETH,
tokenOut: USDC,
amountIn: 1_000000000000000000n,
slippageBps: 50,
})| Option | Type | Description |
|---|---|---|
tokenIn | Address | Input token. Required. |
tokenOut | Address | Output token. Required. |
amountIn | bigint | Input amount in base units. Required. |
slippageBps | number | Max slippage in bps. Default 50. |
include / exclude | string[] | Pin or ban specific adapters. |
simulate()#
Dry-runs a quote against the current block using eth_call. Returns the expected output and a boolean executable flag — essential for liquidation and arbitrage timing.
const sim = await rx.simulate(quote)
if (!sim.executable) {
// route decayed — re-quote or abort before spending gas
return
}
console.log(sim.amountOut)settle()#
Submits the route on-chain with a wallet client. Handles the minimum-out guard, recipient, and deadline, and returns the transaction hash.
const { hash, amountOut } = await rx.settle({
quote,
wallet,
recipient: account.address,
deadline: Math.floor(Date.now() / 1000) + 45,
})Deadlines are enforced on-chain
The Router reverts once the deadline passes. Keep it tight for MEV-sensitive trades.Batching#
Quote several trades in parallel with a single call. Useful for scanning many liquidation opportunities at once without serial round-trips.
const quotes = await rx.quoteBatch([
{ tokenIn: WETH, tokenOut: USDC, amountIn: 1n * 10n ** 18n },
{ tokenIn: WBTC, tokenOut: DAI, amountIn: 5n * 10n ** 7n },
])
const best = quotes
.filter((q) => q.ok)
.sort((a, b) => Number(b.value.netOut - a.value.netOut))[0]Types#
The SDK is fully typed. The core shapes you will work with:
interface Quote {
chainId: number
amountIn: bigint
amountOut: bigint
amountOutMin: bigint
gasEstimate: bigint
priceImpactBps: number
route: RouteHop[]
calldata: `0x${string}`
to: `0x${string}`
}
interface RouteHop {
adapter: string
tokenIn: `0x${string}`
tokenOut: `0x${string}`
share: number // 0..1 portion of input routed through this hop
}- See the Integration guide for the underlying contract interface.
- Every SDK method maps 1:1 to an API endpoint if you prefer raw HTTP.