Getting Started with SwapKit
SwapKit is a comprehensive SDK that unifies blockchain interactions across 20+ chains. This guide will walk you through installation, setup, and building your first cross-chain application.
Prerequisites
Section titled “Prerequisites”Before starting, ensure you have:
- Node.js 18+ or Bun installed
- Basic knowledge of JavaScript/TypeScript
- A code editor (VS Code recommended)
Installation
Section titled “Installation”bun add @swapkit/sdk
pnpm add @swapkit/sdk
npm install @swapkit/sdk
yarn add @swapkit/sdk
Basic Setup
Section titled “Basic Setup”1. Import and Initialize SwapKit
Section titled “1. Import and Initialize SwapKit”import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit } from '@swapkit/sdk';
// Create a SwapKit instance with default configuration
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
2. Configure SwapKit (Optional)
Section titled “2. Configure SwapKit (Optional)”For production applications, you’ll want to add your own API keys and custom settings. See our Configuration Guide for detailed setup:
import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit({
config?: SKConfigState | undefined
config: {
apiKeys?: Partial<{
blockchair: string;
keepKey: string;
swapKit: string;
walletConnectProjectId: string;
}> | undefined
apiKeys: {
walletConnectProjectId?: string | undefined
walletConnectProjectId: 'your-project-id', // Get from cloud.walletconnect.com
blockchair?: string | undefined
blockchair: 'your-blockchair-key', // Get from blockchair.com/api
swapKit?: string | undefined
swapKit: 'your-swapkit-key', // Get from api.swapkit.dev
},
rpcUrls?: Partial<Record<Chain | StagenetChain, string>> | undefined
rpcUrls: {
ETH?: string | undefined
ETH: 'https://eth-mainnet.g.alchemy.com/v2/your-key',
AVAX?: string | undefined
AVAX: 'https://api.avax.network/ext/bc/C/rpc',
}
}
});
Core Concepts
Section titled “Core Concepts”SwapKit has several fundamental concepts you should understand. For a detailed explanation, see our Core Concepts guide.
1. Chains
Section titled “1. Chains”SwapKit supports 20+ blockchain networks with a unified Chain identifier system:
import { enum Chain
Chain } from '@swapkit/sdk';
// Examples of supported chains
const const ethereum: Chain.Ethereum
ethereum = enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum; // "ETH"
const const bitcoin: Chain.Bitcoin
bitcoin = enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin; // "BTC"
const const cosmos: Chain.Cosmos
cosmos = enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos; // "GAIA"
const const thorchain: Chain.THORChain
thorchain = enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain; // "THOR"
2. AssetValue
Section titled “2. AssetValue”AssetValue is SwapKit’s way of representing amounts of any asset:
import { class AssetValue
AssetValue } from '@swapkit/sdk';
// Native assets
const const eth: AssetValue
eth = class AssetValue
AssetValue.AssetValue.from<{
asset: "ETH.ETH";
value: number;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "ETH.ETH";
value: number;
} & AssetValueFromParams): AssetValue
from({ asset: "ETH.ETH"
asset: 'ETH.ETH', value: number
value: 1 }); // 1 ETH
const const btc: AssetValue
btc = class AssetValue
AssetValue.AssetValue.from<{
asset: "BTC.BTC";
value: number;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "BTC.BTC";
value: number;
} & AssetValueFromParams): AssetValue
from({ asset: "BTC.BTC"
asset: 'BTC.BTC', value: number
value: 0.1 }); // 0.1 BTC
// Tokens include the contract address
const const usdc: AssetValue
usdc = class AssetValue
AssetValue.AssetValue.from<{
asset: "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
value: number;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
value: number;
} & AssetValueFromParams): AssetValue
from({
asset: "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
asset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
value: number
value: 1000
}); // 1000 USDC on Ethereum
3. Wallets
Section titled “3. Wallets”SwapKit supports 20+ wallet types:
import { enum WalletOption
WalletOption } from '@swapkit/sdk';
// Browser extension wallets
const const metamask: WalletOption.METAMASK
metamask = enum WalletOption
WalletOption.function (enum member) WalletOption.METAMASK = "METAMASK"
METAMASK;
const const keplr: WalletOption.KEPLR
keplr = enum WalletOption
WalletOption.function (enum member) WalletOption.KEPLR = "KEPLR"
KEPLR;
// Hardware wallets
const const ledger: WalletOption.LEDGER
ledger = enum WalletOption
WalletOption.function (enum member) WalletOption.LEDGER = "LEDGER"
LEDGER;
// Software wallets
const const keystore: WalletOption.KEYSTORE
keystore = enum WalletOption
WalletOption.function (enum member) WalletOption.KEYSTORE = "KEYSTORE"
KEYSTORE;
Common Use Cases
Section titled “Common Use Cases”Connect a Wallet
Section titled “Connect a Wallet”import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, enum Chain
Chain, enum WalletOption
WalletOption } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
// Connect Keystore wallet (mnemonic phrase)
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
ARB?: DerivationPathArray | undefined;
AVAX?: DerivationPathArray | undefined;
... 21 more ...;
TRX?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>
connectKeystore(
[enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin],
'your twelve word mnemonic phrase here'
);
// Connect MetaMask (EVM chains only)
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>
connectEVMWallet([enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum], enum WalletOption
WalletOption.function (enum member) WalletOption.METAMASK = "METAMASK"
METAMASK);
// Connect Keplr (Cosmos chains)
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>
connectKeplr([enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos, enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain]);
// Connect Cosmostation (Cosmos chains)
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.Property 'connectCosmostation' does not exist on type '{ chainflip: { supportedSwapkitProviders: ProviderName[]; } & { swap: (swapParams: RequestSwapDepositAddressParams) => Promise<string>; }; ... 5 more ...; near: { ...; } & { ...; }; } & { ...; } & { ...; }'.connectCosmostation([enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos, enum Chain
Chain.function (enum member) Chain.THORChain = "THOR"
THORChain]);
// Get all connected wallets
const const wallets: {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 22 more ...;
TRX: ChainWallet<...> & {
...;
};
}
wallets = const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getAllWallets: () => {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 22 more ...;
TRX: ChainWallet<...> & {
...;
};
}
getAllWallets();
Get Wallet Balances
Section titled “Get Wallet Balances”import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, enum Chain
Chain } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
// Get balance for a specific chain
const const ethBalance: AssetValue[]
ethBalance = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getBalance: <Chain.Ethereum, boolean>(chain: Chain.Ethereum, refresh?: boolean | undefined) => AssetValue[] | Promise<AssetValue[]>
getBalance(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
const const btcBalance: AssetValue[]
btcBalance = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getBalance: <Chain.Bitcoin, boolean>(chain: Chain.Bitcoin, refresh?: boolean | undefined) => AssetValue[] | Promise<AssetValue[]>
getBalance(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
// Force refresh balance (bypass cache)
const const freshBalance: AssetValue[]
freshBalance = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getBalance: <Chain.Ethereum, true>(chain: Chain.Ethereum, refresh?: true | undefined) => Promise<AssetValue[]>
getBalance(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, true);
// Get wallet with balance
const const walletWithBalance: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 22 more ... | ChainWallet<...>) & {
...;
}
walletWithBalance = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getWalletWithBalance: <Chain.Ethereum>(chain: Chain.Ethereum, scamFilter?: boolean) => Promise<((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 22 more ... | ChainWallet<...>) & {
...;
}>
getWalletWithBalance(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Address: ${const walletWithBalance: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 22 more ... | ChainWallet<...>) & {
...;
}
walletWithBalance.address: string
address}`);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Balance: ${const walletWithBalance: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 22 more ... | ChainWallet<...>) & {
...;
}
walletWithBalance.balance: AssetValue[]
balance}`);
Perform a Swap
Section titled “Perform a Swap”Use the SwapKit API to get quotes and execute swaps:
import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, enum Chain
Chain, enum FeeOption
FeeOption, const SwapKitApi: {
mayachainMidgard: {
getLiquidityPositionRaw: (address: string) => Promise<MemberDetailsMayachain>;
getNameDetails: (name: string) => Promise<THORNameDetails>;
getNamesByAddress: (address: string) => Promise<...>;
getNamesByOwner: (address: string) => Promise<...>;
getLiquidityPosition: (address: string) => Promise<...>;
};
... 14 more ...;
getChainflipDepositChannel(body: BrokerDepositChannelParams): Promise<...>;
}
SwapKitApi } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
// Step 1: Get a quote
const const quoteParams: {
sellAsset: string;
sellAmount: string;
buyAsset: string;
sourceAddress: string;
destinationAddress: string;
slippage: number;
}
quoteParams = {
sellAsset: string
sellAsset: 'ETH.ETH',
sellAmount: string
sellAmount: '1000000000000000000', // 1 ETH in wei
buyAsset: string
buyAsset: 'BTC.BTC',
sourceAddress: string
sourceAddress: const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getAddress: <Chain.Ethereum>(chain: Chain.Ethereum) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum),
destinationAddress: string
destinationAddress: const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.getAddress: <Chain.Bitcoin>(chain: Chain.Bitcoin) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin),
slippage: number
slippage: 3, // 3% slippage tolerance
};
const { const routes: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}[]
routes } = await const SwapKitApi: {
mayachainMidgard: {
getLiquidityPositionRaw: (address: string) => Promise<MemberDetailsMayachain>;
getNameDetails: (name: string) => Promise<THORNameDetails>;
getNamesByAddress: (address: string) => Promise<...>;
getNamesByOwner: (address: string) => Promise<...>;
getLiquidityPosition: (address: string) => Promise<...>;
};
... 14 more ...;
getChainflipDepositChannel(body: BrokerDepositChannelParams): Promise<...>;
}
SwapKitApi.function getSwapQuote(json: QuoteRequest): Promise<{
quoteId: string;
routes: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
... 14 more ...;
estimatedTime?: {
...;
} | undefined;
}[];
error?: string | undefined;
providerErrors?: {
...;
}[] | undefined;
}>
getSwapQuote(const quoteParams: {
sellAsset: string;
sellAmount: string;
buyAsset: string;
sourceAddress: string;
destinationAddress: string;
slippage: number;
}
quoteParams);
// Step 2: Review the quote
const const bestRoute: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}
bestRoute = const routes: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}[]
routes[0];
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Expected output: ${const bestRoute: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}
bestRoute.expectedBuyAmount: string
expectedBuyAmount}`);
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Fees:`, const bestRoute: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}
bestRoute.Property 'fee' does not exist on type '{ providers: ProviderName[]; sellAsset: string; sellAmount: string; buyAsset: string; expectedBuyAmount: string; expectedBuyAmountMaxSlippage: string; sourceAddress: string; ... 12 more ...; estimatedTime?: { ...; } | undefined; }'. Did you mean 'fees'?fee);
// Step 3: Execute the swap
const const txHash: any
txHash = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.swap: <"chainflip" | "evm" | "mayachain" | "thorchain" | "radix" | "solana" | "near">({ route, pluginName, ...rest }: SwapParams<"chainflip" | "evm" | "mayachain" | "thorchain" | "radix" | "solana" | "near", {
providers: ProviderName[];
... 18 more ...;
estimatedTime?: {
...;
} | undefined;
}>) => any
swap({
route: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}
route: const bestRoute: {
providers: ProviderName[];
sellAsset: string;
sellAmount: string;
buyAsset: string;
expectedBuyAmount: string;
expectedBuyAmountMaxSlippage: string;
sourceAddress: string;
... 12 more ...;
estimatedTime?: {
...;
} | undefined;
}
bestRoute,
feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast
});
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log(`Swap transaction: ${const txHash: any
txHash}`);
Send Transactions
Section titled “Send Transactions”import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, class AssetValue
AssetValue, enum FeeOption
FeeOption, enum Chain
Chain } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
// Simple ETH transfer
const const ethAmount: AssetValue
ethAmount = class AssetValue
AssetValue.AssetValue.from<{
asset: "ETH.ETH";
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "ETH.ETH";
value: string;
} & AssetValueFromParams): AssetValue
from({ asset: "ETH.ETH"
asset: 'ETH.ETH', value: string
value: '0.1' });
const const txHash: any
txHash = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>
transfer({
assetValue: AssetValue
assetValue: const ethAmount: AssetValue
ethAmount,
recipient: string
recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f6E321',
memo?: string | undefined
memo: 'Payment for services', // Optional
feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast
});
// Bitcoin transfer with custom fee
const const btcAmount: AssetValue
btcAmount = class AssetValue
AssetValue.AssetValue.from<{
asset: "BTC.BTC";
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: "BTC.BTC";
value: string;
} & AssetValueFromParams): AssetValue
from({ asset: "BTC.BTC"
asset: 'BTC.BTC', value: string
value: '0.001' });
const const btcTxHash: any
btcTxHash = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>
transfer({
assetValue: AssetValue
assetValue: const btcAmount: AssetValue
btcAmount,
recipient: string
recipient: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Average = "average"
Average
});
// Ripple (XRP) transfer
const const xrpAmount: AssetValue
xrpAmount = class AssetValue
AssetValue.AssetValue.from<{
asset: string;
value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
asset: string;
value: string;
} & AssetValueFromParams): AssetValue
from({ asset: string
asset: 'XRP.XRP', value: string
value: '10' });
const const xrpTxHash: any
xrpTxHash = await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>
transfer({
assetValue: AssetValue
assetValue: const xrpAmount: AssetValue
xrpAmount,
recipient: string
recipient: 'rBaaxNpAKxELKXkJpSCCJQTkQMTYrcPQPv',
memo?: string | undefined
memo: 'Invoice #12345', // Optional destination tag or memo
feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast
});
Advanced Usage
Section titled “Advanced Usage”Using Core + Plugins (Modular Approach)
Section titled “Using Core + Plugins (Modular Approach)”For smaller bundle sizes, use only the components you need:
import { function SwapKit<Plugins extends ReturnType<typeof createPlugin>, Wallets extends ReturnType<typeof createWallet>>({ config, plugins, wallets, }?: {
config?: SKConfigState;
plugins?: Plugins;
wallets?: Wallets;
}): { [key in keyof Plugins]: ReturnType<...>; } & ... 1 more ... & {
...;
}
SwapKit, const ThorchainPlugin: {
thorchain: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders: ProviderName[];
} & {
addLiquidity: ({ baseAssetValue, assetValue, baseAssetAddr, assetAddr, isPendingSymmAsset, mode, }: AddLiquidityParams) => Promise<...>;
... 11 more ...;
withdraw: ({ memo, assetValue, percent, from, to }: WithdrawParams) => Promise<...>;
};
}
ThorchainPlugin, const keystoreWallet: {
connectKeystore: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
ARB?: DerivationPathArray | undefined;
... 22 more ...;
TRX?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 19 more ... | Chain.Tron)[];
};
}
keystoreWallet, const ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 13 more ... | Chain.THORChain)[];
};
}
ledgerWallet } from '@swapkit/sdk';
const const swapKit: {
thorchain: {
supportedSwapkitProviders: ProviderName[];
} & {
addLiquidity: ({ baseAssetValue, assetValue, baseAssetAddr, assetAddr, isPendingSymmAsset, mode, }: AddLiquidityParams) => Promise<{
baseAssetTx: string | undefined;
assetTx: string | undefined;
}>;
... 11 more ...;
withdraw: ({ memo, assetValue, percent, from, to }: WithdrawParams) => Promise<...>;
};
} & {
...;
} & {
...;
}
swapKit = SwapKit<{
thorchain: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders: ProviderName[];
} & {
addLiquidity: ({ baseAssetValue, assetValue, baseAssetAddr, assetAddr, isPendingSymmAsset, mode, }: AddLiquidityParams) => Promise<...>;
... 11 more ...;
withdraw: ({ memo, assetValue, percent, from, to }: WithdrawParams) => Promise<...>;
};
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
plugins?: {
thorchain: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders: ProviderName[];
} & {
addLiquidity: ({ baseAssetValue, assetValue, baseAssetAddr, assetAddr, isPendingSymmAsset, mode, }: AddLiquidityParams) => Promise<...>;
... 11 more ...;
withdraw: ({ memo, assetValue, percent, from, to }: WithdrawParams) => Promise<...>;
};
} | undefined
plugins: {
...const ThorchainPlugin: {
thorchain: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders: ProviderName[];
} & {
addLiquidity: ({ baseAssetValue, assetValue, baseAssetAddr, assetAddr, isPendingSymmAsset, mode, }: AddLiquidityParams) => Promise<...>;
... 11 more ...;
withdraw: ({ memo, assetValue, percent, from, to }: WithdrawParams) => Promise<...>;
};
}
ThorchainPlugin,
},
wallets?: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 13 more ... | Chain.THORChain)[];
};
connectKeystore: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
ARB?: DerivationPathArray | undefined;
... 22 more ...;
TRX?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 19 more ... | Chain.Tron)[];
};
} | undefined
wallets: {
...const keystoreWallet: {
connectKeystore: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
ARB?: DerivationPathArray | undefined;
... 22 more ...;
TRX?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 19 more ... | Chain.Tron)[];
};
}
keystoreWallet,
...const ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 13 more ... | Chain.THORChain)[];
};
}
ledgerWallet,
},
});
Direct Toolbox Usage
Section titled “Direct Toolbox Usage”For low-level blockchain operations:
import { function getToolbox<T extends Chain.Radix | Chain.Ripple | Chain.Solana | Chain.Tron | EVMChain | UTXOChain | CosmosChain | SubstrateChain>(chain: T, params?: ToolboxParams[T]): Promise<Toolboxes[T]>
getToolbox, enum Chain
Chain } from '@swapkit/sdk';
const const address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"
address = 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh';
const const btcToolbox: Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}>
btcToolbox = getToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: undefined): Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}>
getToolbox(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
const const isValid: any
isValid = const btcToolbox: Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}>
btcToolbox.Property 'validateAddress' does not exist on type 'Promise<{ accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & { outputs: TargetOutput[]; chain: UTXOChain; }) => { inputs: (UTXOType | UTXOInputWithScriptType)[]; outputs: TargetOutput[]; fee: number; } | { ...; }; ... 13 more ...; estimateMaxSendableAmount: ({ from, memo...'.validateAddress(const address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"
address);
const const balance: any
balance = await const btcToolbox: Promise<{
accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & {
outputs: TargetOutput[];
chain: UTXOChain;
}) => {
...;
} | {
...;
};
... 13 more ...;
estimateMaxSendableAmount: ({ from, memo, feeRate, feeOptionKey, recipients, }: {
from: string;
memo?: string;
feeRate?: number;
feeOptionKey?: FeeOption;
recipients?: number | TargetOutput[];
}) => Promise<...>;
} | {
...;
}>
btcToolbox.Property 'getBalance' does not exist on type 'Promise<{ accumulative: ({ inputs, outputs, feeRate: initialFeeRate, chain, }: UTXOCalculateTxSizeParams & { outputs: TargetOutput[]; chain: UTXOChain; }) => { inputs: (UTXOType | UTXOInputWithScriptType)[]; outputs: TargetOutput[]; fee: number; } | { ...; }; ... 13 more ...; estimateMaxSendableAmount: ({ from, memo...'.getBalance(const address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"
address);
Custom Plugin Development
Section titled “Custom Plugin Development”Create your own plugin to extend SwapKit:
import { function SwapKit<Plugins extends ReturnType<typeof createPlugin>, Wallets extends ReturnType<typeof createWallet>>({ config, plugins, wallets, }?: {
config?: SKConfigState;
plugins?: Plugins;
wallets?: Wallets;
}): { [key in keyof Plugins]: ReturnType<...>; } & ... 1 more ... & {
...;
}
SwapKit } from '@swapkit/sdk';
const const MyCustomPlugin: {
myCustomMethod: (params: any) => Promise<{
success: boolean;
}>;
getCustomData: () => Promise<{
data: string;
}>;
}
MyCustomPlugin = {
myCustomMethod: (params: any) => Promise<{
success: boolean;
}>
myCustomMethod: async (params: any
params: any) => {
// Your custom logic here
return { success: boolean
success: true };
},
// Add custom functionality
getCustomData: () => Promise<{
data: string;
}>
getCustomData: async () => {
console.Console.log(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stdout` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout
```
See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args) for more information.log('Fetching custom data');
return { data: string
data: 'custom-data' };
}
};
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
[x: string]: (...params: any[]) => Promise<boolean>;
} & {
...;
}
swapKit = SwapKit<{
[x: string]: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<...>;
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
Type '{ myCustomMethod: (params: any) => Promise<{ success: boolean; }>; getCustomData: () => Promise<{ data: string; }>; }' is not assignable to type '{ [x: string]: (pluginParams: SwapKitPluginParams) => { supportedSwapkitProviders?: string[] | undefined; } & Record<string, unknown>; }'.
Property 'myCustomMethod' is incompatible with index signature.
Type '(params: any) => Promise<{ success: boolean; }>' is not assignable to type '(pluginParams: SwapKitPluginParams) => { supportedSwapkitProviders?: string[] | undefined; } & Record<string, unknown>'.
Type 'Promise<{ success: boolean; }>' is not assignable to type '{ supportedSwapkitProviders?: string[] | undefined; } & Record<string, unknown>'.
Type 'Promise<{ success: boolean; }>' is not assignable to type 'Record<string, unknown>'.
Index signature for type 'string' is missing in type 'Promise<{ success: boolean; }>'.plugins: {
...const MyCustomPlugin: {
myCustomMethod: (params: any) => Promise<{
success: boolean;
}>;
getCustomData: () => Promise<{
data: string;
}>;
}
MyCustomPlugin,
},
});
// Use your custom method
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
[x: string]: (...params: any[]) => Promise<boolean>;
} & {
...;
}
swapKit.{
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown> & ((...params: any[]) => Promise<boolean>)
myCustomMethod({ customParam: string
customParam: 'value' });
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
[x: string]: (...params: any[]) => Promise<boolean>;
} & {
...;
}
swapKit.{
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown> & ((...params: any[]) => Promise<boolean>)
getCustomData();
Error Handling
Section titled “Error Handling”SwapKit uses typed errors for better debugging:
import { function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit, class SwapKitError
SwapKitError, enum FeeOption
FeeOption } from '@swapkit/sdk';
const const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit = function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
createSwapKit();
try {
// Example: attempting a swap with a route object
const const route: {
sellAsset: string;
buyAsset: string;
expectedBuyAmount: string;
}
route = {
sellAsset: string
sellAsset: 'ETH.ETH',
buyAsset: string
buyAsset: 'BTC.BTC',
expectedBuyAmount: string
expectedBuyAmount: '0.001',
// ... other route properties
};
await const swapKit: {
chainflip: {
supportedSwapkitProviders: ProviderName[];
} & {
swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
};
... 5 more ...;
near: {
...;
} & {
...;
};
} & {
...;
} & {
...;
}
swapKit.swap: <"chainflip" | "evm" | "mayachain" | "thorchain" | "radix" | "solana" | "near">({ route, pluginName, ...rest }: SwapParams<"chainflip" | "evm" | "mayachain" | "thorchain" | "radix" | "solana" | "near", {
providers: ProviderName[];
... 18 more ...;
estimatedTime?: {
...;
} | undefined;
}>) => any
swap({
Type '{ sellAsset: string; buyAsset: string; expectedBuyAmount: string; }' is missing the following properties from type '{ providers: ProviderName[]; sellAsset: string; sellAmount: string; buyAsset: string; expectedBuyAmount: string; expectedBuyAmountMaxSlippage: string; sourceAddress: string; ... 12 more ...; estimatedTime?: { ...; } | undefined; }': providers, sellAmount, expectedBuyAmountMaxSlippage, sourceAddress, and 6 more.route,
feeOptionKey?: FeeOption | undefined
feeOptionKey: enum FeeOption
FeeOption.function (enum member) FeeOption.Fast = "fast"
Fast
});
} catch (var error: unknown
error) {
if (var error: unknown
error instanceof class SwapKitError
SwapKitError) {
console.Console.error(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stderr` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const code = 5;
console.error('error #%d', code);
// Prints: error #5, to stderr
console.error('error', code);
// Prints: error 5, to stderr
```
If formatting elements (e.g. `%d`) are not found in the first string then
[`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options) is called on each argument and the
resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)
for more information.error('SwapKit Error:', var error: SwapKitError
error.Error.message: string
message);
// Error may have additional properties
console.Console.error(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stderr` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const code = 5;
console.error('error #%d', code);
// Prints: error #5, to stderr
console.error('error', code);
// Prints: error 5, to stderr
```
If formatting elements (e.g. `%d`) are not found in the first string then
[`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options) is called on each argument and the
resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)
for more information.error('Full error:', var error: SwapKitError
error);
} else {
console.Console.error(message?: any, ...optionalParams: any[]): void (+3 overloads)
Prints to `stderr` with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to [`printf(3)`](http://man7.org/linux/man-pages/man3/printf.3.html)
(the arguments are all passed to [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)).
```js
const code = 5;
console.error('error #%d', code);
// Prints: error #5, to stderr
console.error('error', code);
// Prints: error 5, to stderr
```
If formatting elements (e.g. `%d`) are not found in the first string then
[`util.inspect()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilinspectobject-options) is called on each argument and the
resulting string values are concatenated. See [`util.format()`](https://nodejs.org/docs/latest-v24.x/api/util.html#utilformatformat-args)
for more information.error('Unexpected error:', var error: unknown
error);
}
}
Next Steps
Section titled “Next Steps”Now that you understand the basics:
Essential Reading
Section titled “Essential Reading”- Core Concepts - Master AssetValue, error handling, and types
- Configuration - Set up API keys and customize settings
- API Reference - Explore all available API methods
Build Your Application
Section titled “Build Your Application”- Connect Wallets - Deep dive into wallet integration
- Perform Swaps - Implement cross-chain swaps
- Send Transactions - Handle transfers and tracking
Advanced Topics
Section titled “Advanced Topics”- THORChain Features - Liquidity, and THORNames
- Advanced Features - Multi-chain ops and synthetics
- Toolbox Usage - Direct blockchain operations
Extend SwapKit
Section titled “Extend SwapKit”- Create Custom Plugin - Add new protocols
- Create Custom Wallet - Integrate new wallets
- Framework Integration - Use with Next.js, Vite, etc.
Need Help?
Section titled “Need Help?”- 💬 Join our Discord for community support
- 🐛 Report issues on GitHub
- 📚 Browse the API Reference for detailed documentation
Happy building with SwapKit! 🚀