Type-safe TypeScript SDK for the SwapKit API. Auto-generated from OpenAPI specs with named domain types and full request/response typing.
npm install @swapkit/api-sdk-typescript
# or
bun add @swapkit/api-sdk-typescriptFor the bleeding-edge build tracking the API's develop branch, install the nightly tag:
npm install @swapkit/api-sdk-typescript@nightlyimport{configureSwapKit,SwapKitService}from"@swapkit/api-sdk-typescript";// Configure once at startupconfigureSwapKit({apiKey: "your-api-key"});// Use named service methods — fully typedconst{data: providers}=awaitSwapKitService.getProviders();const{data: quote, error }=awaitSwapKitService.getQuote({body: {sellAsset: "ETH.ETH",buyAsset: "BTC.BTC",sellAmount: "1",sourceAddress: "0x...",destinationAddress: "bc1...",},});if(error){console.error("Quote failed:",error);}else{console.log(`Got ${quote.routes.length} routes for quote ${quote.quoteId}`);}| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | (required) | Your SwapKit API key |
baseUrl | string | https://api.swapkit.dev | API base URL override |
// Production (default)configureSwapKit({apiKey: "sk_live_..."});// StagingconfigureSwapKit({apiKey: "sk_test_...",baseUrl: "https://dev-api.swapkit.dev",});All API methods are available as static methods on the SwapKitService class:
| Method | HTTP | Endpoint |
|---|---|---|
getProviders() | GET | /providers |
getTokens({ query? }) | GET | /tokens |
getSwapTo({ query }) | GET | /swapTo |
getSwapFrom({ query }) | GET | /swapFrom |
getQuote({ body }) | POST | /v3/quote |
getSwap({ body }) | POST | /v3/swap |
trackTransaction({ body }) | POST | /track |
screenAddress({ body }) | POST | /screen |
getGasPrices() | GET | /gas |
getGasHistory({ query? }) | GET | /gas/history |
getCachedPrice({ body }) | POST | /price/cached-price |
createBrokerChannel({ body }) | POST | /chainflip/broker/channel |
// Get available providersconst{data: providers}=awaitSwapKitService.getProviders();// Get tokens for a providerconst{data: tokens}=awaitSwapKitService.getTokens({query: {provider: "THORCHAIN"},});// Get available buy assets for a sell assetconst{data: buyAssets}=awaitSwapKitService.getSwapTo({query: {sellAsset: "ETH.ETH"},});// Get a quoteconst{ data, error }=awaitSwapKitService.getQuote({body: {sellAsset: "ETH.ETH",buyAsset: "BTC.BTC",sellAmount: "1",slippage: 3,providers: ["THORCHAIN"],},});// Execute a swapconst{data: swap}=awaitSwapKitService.getSwap({body: {routeId: route.routeId,sourceAddress: "0xabc...",destinationAddress: "bc1xyz...",},});// Track a transactionconst{data: status}=awaitSwapKitService.trackTransaction({body: {hash: "0xabc...",chainId: "1"},});// Screen an addressconst{data: screen}=awaitSwapKitService.screenAddress({body: {addresses: ["0xabc..."],chains: ["ETH"]},});// Get gas pricesconst{data: gas}=awaitSwapKitService.getGasPrices();// Get cached token pricesconst{data: prices}=awaitSwapKitService.getCachedPrice({body: {tokens: [{identifier: "ETH.ETH"}],metadata: true},});import{configureSwapKit,SwapKitService}from"@swapkit/api-sdk-typescript";configureSwapKit({apiKey: "your-api-key"});// 1. Get a quoteconst{data: quote}=awaitSwapKitService.getQuote({body: {sellAsset: "ETH.ETH",buyAsset: "BTC.BTC",sellAmount: "1",sourceAddress: "0xYourAddress...",destinationAddress: "bc1YourBtcAddress...",},});if(!quote)thrownewError("Quote failed");// 2. Pick the best routeconstroute=quote.routes.find((r)=>r.meta.tags.includes("RECOMMENDED"))??quote.routes[0];// 3. Execute the swapconst{data: swap}=awaitSwapKitService.getSwap({body: {routeId: route.routeId,sourceAddress: "0xYourAddress...",destinationAddress: "bc1YourBtcAddress...",},});// 4. Track the transactionconst{data: status}=awaitSwapKitService.trackTransaction({body: {hash: "0xBroadcastedTxHash...",chainId: "1"},});console.log(`Status: ${status?.status}`);You can also import SDK functions directly instead of using the service class:
import{postV3Quote,postV3Swap,postTrack}from"@swapkit/api-sdk-typescript";bun run extract:sdk
LOCAL_SPECS_DIR=/tmp/swapkit-specs bun run generate:sdkbun run test:sdkbun run build:sdk