// Introduction
Quickstart
From install to a settled swap. This walkthrough uses the TypeScript SDK; every step also maps to GET /v1/:chain/quote and /swap.
1. Install#
Add the SDK to any TypeScript or JavaScript project.
bash
npm install @routerx.exchange/sdkQuoting works without a wallet. Passing an EIP-1193 provider is required to approve and send swaps.
2. Request a quote#
Create a client for the chain you operate on and ask for the best gas-adjusted route. Amounts are decimal strings in the token's smallest unit.
quote.ts
import { RouterX } from '@routerx.exchange/sdk'
const rx = new RouterX({ chainId: 8453 })
const quote = await rx.swap.quote({
tokenIn: '0x4200000000000000000000000000000000000006', // WETH
tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC
amountIn: '1000000000000000000', // 1 WETH
})
console.log(quote.amountOut)
console.log(quote.offer.path)
console.log(quote.router)The quote is the plan
quote.offer holds the adapter path and amounts. Use rx.swap.buildSwapTx or rx.swap.swap to turn it into calldata / a sent transaction.3. Settle the swap#
Pass a wallet provider so the SDK can approve (if needed) and send the swap in one call.
swap.ts
const rx = new RouterX({
chainId: 8453,
provider: window.ethereum,
})
const { hash, minAmountOut, tx } = await rx.swap.swap({
tokenIn: '0x4200000000000000000000000000000000000006',
tokenOut: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
amountIn: '1000000000000000000',
to: account,
slippage: 0.5,
})
console.log('settled:', hash, minAmountOut)Simulate before you fire
For liquidation and arbitrage flows, callrx.swap.buildSwapTx(…) first and eth_call the resulting tx against the current block before broadcasting.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.
- Use rx.cross for CCTP Composer Cross swaps.