// Introduction
Quickstart
From install to a settled swap. This walkthrough uses the TypeScript SDK, but every step maps to a plain REST call or a direct contract interaction.
1. Install#
Add the SDK to any TypeScript or JavaScript project. It ships with viem as a peer dependency.
bash
npm install @routerx/sdk viemNo account, API key, or allowlisting is required to start quoting.
2. Request a quote#
Create a client for the chain you operate on and ask for the best gas-adjusted route. Amounts are always expressed in the token's smallest unit.
quote.ts
import { RouterX } from '@routerx/sdk'
import { mainnet } from 'viem/chains'
const rx = new RouterX({ chain: mainnet })
const quote = await rx.quote({
tokenIn: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH
tokenOut: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
amountIn: 1_000000000000000000n, // 1 WETH
slippageBps: 50, // 0.5%
})
console.log(quote.amountOut) // expected output, net of fees
console.log(quote.gasEstimate) // gas for the settlement tx
console.log(quote.route) // human-readable path across adaptersThe quote is the plan
Thequote.route object already contains the encoded calldata for settlement. You never re-plan between quoting and execution.3. Settle the route#
Pass a wallet client to turn the quote into a signed, on-chain settlement. RouterX handles approvals, deadline, and the recipient in a single transaction.
settle.ts
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet } from 'viem/chains'
const account = privateKeyToAccount(process.env.PK as `0x${string}`)
const wallet = createWalletClient({ account, chain: mainnet, transport: http() })
const { hash } = await rx.settle({
quote,
wallet,
recipient: account.address,
deadline: Math.floor(Date.now() / 1000) + 60,
})
console.log('settled:', hash)Simulate before you fire
For liquidation and arbitrage flows, callrx.simulate(quote) first. If the route can no longer execute at the current block, settlement is aborted before gas is spent.Next steps#
- Read the Integration guide to wire the router contract into an existing bot.
- Browse the API reference for every quoting and routing parameter.
- Explore the full SDK surface, including batching and multi-hop control.