1.0.2 • Published 5 months ago
@suave-money/sdk v1.0.2
Suave SDK
The Suave SDK enables effective usage of the Suave Bridge Aggregation API from TypeScript or JavaScript. Use this toolkit to find desirable cross-chain swapping routes and handle route execution.
DISCLAIMER: This SDK currently only supports executing routes in a browser-like environment.
Installation
You will need to also have viem installed to get started. To install everything with npm, use this command:
npm install --save @suave_money/sdk viem
Getting Started - Requesting Route Quotes
Here is an example of obtaining route qoutes from Suave:
import { getRoutes, RouteResponse } from '@suave_money/sdk'
// Find a route for USDC on Arbitrum -> DAI on Polygon
const routes: RouteResponse[] = await getRoutes({
inputAmount: '10000000', // 10 USDC
fromChainId: 42161, // Arbitrum
fromToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', // USDC on Arbitrum
toChainId: 137, // Polygon
toToken: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', // DAI on Polygon
})
Getting Started - Executing Route Quotes
Here is an example of executing a route:
import { executeRoute, RouteResponse } from '@suave_money/sdk'
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const client = createWalletClient({
chain: mainnet,
transport: http()
})
const routes: RouteResponse[] = /* ... */
const chosenRoute = routes[0]
await executeRoute(chosenRoute, {
walletClient: client
})