Skip to content
SwapKit is a powerful suite of tools for building blockchain applications.

Core Concepts

Before diving into SwapKit’s features, it’s essential to understand its core concepts. These building blocks are used throughout the SDK and understanding them will make your development experience much smoother.

AssetValue is SwapKit’s primary way of representing amounts of any asset across all supported chains. It handles decimal precision, formatting, and arithmetic operations automatically.

import { class AssetValueAssetValue } from '@swapkit/sdk';

// From decimal value (what users see)
const const oneEth: AssetValueoneEth = class AssetValueAssetValue.
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: numbervalue: 1 }); // From base units (wei, satoshi, etc.) const const oneEthInWei: AssetValueoneEthInWei = class AssetValueAssetValue.
AssetValue.from<{
    asset: "ETH.ETH";
    value: string;
    fromBaseDecimal: boolean;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: never): AssetValue
from
({
Type '"ETH.ETH"' is not assignable to type 'never'.
asset
: 'ETH.ETH',
Type 'string' is not assignable to type 'never'.
value
: '1000000000000000000',
Type 'true' is not assignable to type 'never'.
fromBaseDecimal
: true
}); // Both create the same AssetValue representing 1 ETH

SwapKit uses a consistent format for identifying assets:

// Native assets: CHAIN.SYMBOL
'ETH.ETH'         // Native Ethereum
'BTC.BTC'         // Native Bitcoin
'AVAX.AVAX'       // Native Avalanche

// Tokens: CHAIN.SYMBOL-CONTRACT
'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'     // USDC on Ethereum
'AVAX.USDC-0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E'    // USDC on Avalanche

// Synthetic assets (THORChain)
'ETH/ETH'         // Synthetic ETH
'BTC/BTC'         // Synthetic BTC

AssetValue provides safe arithmetic operations:

const const amount1: anyamount1 = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH.ETH', value: numbervalue: 1.5 });
const const amount2: anyamount2 =
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH.ETH', value: numbervalue: 0.5 });
// Addition const const sum: anysum = const amount1: anyamount1.add(const amount2: anyamount2); // 2 ETH // Subtraction const const difference: anydifference = const amount1: anyamount1.sub(const amount2: anyamount2); // 1 ETH // Multiplication const const doubled: anydoubled = const amount1: anyamount1.mul(2); // 3 ETH // Division const const halved: anyhalved = const amount1: anyamount1.div(2); // 0.75 ETH

Compare AssetValue instances safely:

const const amount1: anyamount1 = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'BTC.BTC', value: numbervalue: 1 });
const const amount2: anyamount2 =
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'BTC.BTC', value: numbervalue: 0.5 });
const amount1: anyamount1.gt(const amount2: anyamount2); // true - greater than const amount1: anyamount1.gte(const amount2: anyamount2); // true - greater than or equal const amount1: anyamount1.lt(const amount2: anyamount2); // false - less than const amount1: anyamount1.lte(const amount2: anyamount2); // false - less than or equal const amount1: anyamount1.eq(const amount2: anyamount2); // false - equal

Format values for display:

const const btcAmount: anybtcAmount = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'BTC.BTC', value: numbervalue: 0.00123456 });
// Format with significant digits const btcAmount: anybtcAmount.toSignificant(4); // "0.001235" // Format as currency const btcAmount: anybtcAmount.toCurrency('USD', 45000); // "$55.56" // Format with abbreviation const const largeAmount: anylargeAmount =
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH.ETH', value: numbervalue: 1234567 });
const largeAmount: anylargeAmount.toAbbreviation(); // "1.23M" // Get raw values const btcAmount: anybtcAmount.getValue('string'); // "0.00123456" const btcAmount: anybtcAmount.getBaseValue('string'); // "123456" (in satoshis)

Check asset properties:

const const ethAmount: anyethAmount = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH.ETH', value: numbervalue: 1 });
const const usdcAmount: anyusdcAmount =
Cannot find name 'AssetValue'.
AssetValue
.from({
asset: stringasset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', value: numbervalue: 100 }); const const synthEth: anysynthEth =
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH/ETH', value: numbervalue: 1 });
const ethAmount: anyethAmount.isGasAsset(); // true - native asset const usdcAmount: anyusdcAmount.isGasAsset(); // false - token const synthEth: anysynthEth.isSynthetic(); // true - synthetic asset

SwapKitNumber provides utilities for safe numeric operations with BigInt support:

import { class SwapKitNumberSwapKitNumber } from '@swapkit/sdk';

// Create from various inputs
const const num1: SwapKitNumbernum1 = new new SwapKitNumber(params: SKBigIntParams): SwapKitNumberSwapKitNumber(123.456);
const const num2: SwapKitNumbernum2 = new new SwapKitNumber(params: SKBigIntParams): SwapKitNumberSwapKitNumber('789.012');
const const num3: SwapKitNumbernum3 = new new SwapKitNumber(params: SKBigIntParams): SwapKitNumberSwapKitNumber({ value: string | numbervalue: 100, decimal: numberdecimal: 18 });

// Arithmetic operations
const const sum: SwapKitNumbersum = const num1: SwapKitNumbernum1.BigIntArithmetics.add(...args: InitialisationValueType[]): SwapKitNumberadd(const num2: SwapKitNumbernum2);
const const product: SwapKitNumberproduct = const num1: SwapKitNumbernum1.BigIntArithmetics.mul(...args: InitialisationValueType[]): SwapKitNumbermul(const num2: SwapKitNumbernum2);

// Formatting
const num1: SwapKitNumbernum1.BigIntArithmetics.toSignificant(significantDigits?: number): stringtoSignificant(4); // "123.5"
const num1: SwapKitNumbernum1.BigIntArithmetics.toFixed(fixedDigits?: number): stringtoFixed(2); // "123.46"

SwapKit uses consistent chain identifiers across the entire SDK:

import { enum ChainChain } from '@swapkit/sdk';

// EVM Chains
enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum         // "ETH"
enum ChainChain.function (enum member) Chain.Avalanche = "AVAX"Avalanche       // "AVAX"
enum ChainChain.function (enum member) Chain.BinanceSmartChain = "BSC"BinanceSmartChain // "BSC"
enum ChainChain.function (enum member) Chain.Polygon = "MATIC"Polygon         // "MATIC"
enum ChainChain.function (enum member) Chain.Arbitrum = "ARB"Arbitrum        // "ARB"
enum ChainChain.function (enum member) Chain.Optimism = "OP"Optimism        // "OP"
enum ChainChain.function (enum member) Chain.Base = "BASE"Base            // "BASE"

// UTXO Chains
enum ChainChain.function (enum member) Chain.Bitcoin = "BTC"Bitcoin         // "BTC"
enum ChainChain.function (enum member) Chain.BitcoinCash = "BCH"BitcoinCash     // "BCH"
enum ChainChain.function (enum member) Chain.Litecoin = "LTC"Litecoin        // "LTC"
enum ChainChain.function (enum member) Chain.Dogecoin = "DOGE"Dogecoin        // "DOGE"
enum ChainChain.function (enum member) Chain.Dash = "DASH"Dash            // "DASH"
enum ChainChain.
Property 'Zcash' does not exist on type 'typeof Chain'.
Zcash
// "ZEC"
// Cosmos Chains enum ChainChain.function (enum member) Chain.Cosmos = "GAIA"Cosmos // "GAIA" enum ChainChain.function (enum member) Chain.THORChain = "THOR"THORChain // "THOR" enum ChainChain.function (enum member) Chain.Maya = "MAYA"Maya // "MAYA" enum ChainChain.function (enum member) Chain.Kujira = "KUJI"Kujira // "KUJI" // Other Chains enum ChainChain.function (enum member) Chain.Solana = "SOL"Solana // "SOL" enum ChainChain.function (enum member) Chain.Polkadot = "DOT"Polkadot // "DOT" enum ChainChain.function (enum member) Chain.Chainflip = "FLIP"Chainflip // "FLIP" enum ChainChain.function (enum member) Chain.Radix = "XRD"Radix // "XRD" enum ChainChain.function (enum member) Chain.Ripple = "XRP"Ripple // "XRP"

SwapKit uses a typed error system for better debugging:

The base error class with additional context:

import { class SwapKitErrorSwapKitError } from '@swapkit/sdk';

try {
  await 
Cannot find name 'swapKit'.
swapKit
No value exists in scope for the shorthand property 'route'. Either declare one or provide an initializer.
.swap({ route });
} catch (var error: unknownerror) { if (var error: unknownerror instanceof class SwapKitErrorSwapKitError) { // Access error details 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.
@sincev0.1.100
error
('Error:', var error: SwapKitErrorerror.Error.message: stringmessage);
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.
@sincev0.1.100
error
('Code:', var error: SwapKitErrorerror.
Property 'code' does not exist on type 'SwapKitError'.
code
);
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.
@sincev0.1.100
error
('Details:', var error: SwapKitErrorerror.
Property 'details' does not exist on type 'SwapKitError'.
details
);
} }

SwapKit uses standardized error codes:

// Wallet errors
"wallet_not_found"
"wallet_connection_failed"
"wallet_insufficient_funds"

// Transaction errors
"transaction_failed"
"transaction_rejected"
"transaction_timeout"

// API errors
"api_request_failed"
"api_rate_limit"
"api_invalid_response"

// Validation errors
"invalid_address"
"invalid_amount"
"invalid_chain"

Errors include helpful context:

'try' expected.
catch
(var error: unknownerror) {
if (var error: unknownerror instanceof
Cannot find name 'SwapKitError'.
SwapKitError
) {
// Error might include: // - Transaction hash // - Chain information // - Wallet address // - API response 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.
@sincev0.1.100
log
('Context:',
'error' is of type 'unknown'.
error
.info);
} }

SwapKit supports various wallet types through the WalletOption enum:

import { enum WalletOptionWalletOption } from '@swapkit/sdk';

enum WalletOptionWalletOption.function (enum member) WalletOption.METAMASK = "METAMASK"METAMASK
enum WalletOptionWalletOption.
Property 'COINBASE' does not exist on type 'typeof WalletOption'.
COINBASE
enum WalletOptionWalletOption.function (enum member) WalletOption.OKX = "OKX"OKX enum WalletOptionWalletOption.function (enum member) WalletOption.BITGET = "BITGET"BITGET enum WalletOptionWalletOption.function (enum member) WalletOption.EXODUS = "EXODUS"EXODUS enum WalletOptionWalletOption.function (enum member) WalletOption.KEPLR = "KEPLR"KEPLR enum WalletOptionWalletOption.function (enum member) WalletOption.LEAP = "LEAP"LEAP enum WalletOptionWalletOption.function (enum member) WalletOption.COSMOSTATION = "COSMOSTATION"COSMOSTATION enum WalletOptionWalletOption.function (enum member) WalletOption.LEDGER = "LEDGER"LEDGER enum WalletOptionWalletOption.function (enum member) WalletOption.TREZOR = "TREZOR"TREZOR enum WalletOptionWalletOption.function (enum member) WalletOption.KEEPKEY = "KEEPKEY"KEEPKEY enum WalletOptionWalletOption.function (enum member) WalletOption.WALLETCONNECT = "WALLETCONNECT"WALLETCONNECT enum WalletOptionWalletOption.function (enum member) WalletOption.KEYSTORE = "KEYSTORE"KEYSTORE enum WalletOptionWalletOption.
Property 'POLKADOTJS' does not exist on type 'typeof WalletOption'. Did you mean 'POLKADOT_JS'?
POLKADOTJS
enum WalletOptionWalletOption.function (enum member) WalletOption.TALISMAN = "TALISMAN"TALISMAN enum WalletOptionWalletOption.function (enum member) WalletOption.PHANTOM = "PHANTOM"PHANTOM enum WalletOptionWalletOption.function (enum member) WalletOption.ONEKEY = "ONEKEY"ONEKEY enum WalletOptionWalletOption.
Property 'RADIX_MOBILE' does not exist on type 'typeof WalletOption'.
RADIX_MOBILE
enum WalletOptionWalletOption.function (enum member) WalletOption.BRAVE = "BRAVE"BRAVE enum WalletOptionWalletOption.
Property 'TRUSTWALLET' does not exist on type 'typeof WalletOption'.
TRUSTWALLET
enum WalletOptionWalletOption.
Property 'XDEFI' does not exist on type 'typeof WalletOption'.
XDEFI

Control transaction fees with the FeeOption enum:

import { enum FeeOptionFeeOption } from '@swapkit/sdk';

// Available fee options
enum FeeOptionFeeOption.function (enum member) FeeOption.Average = "average"Average  // Standard fee
enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast     // 1.5x standard
enum FeeOptionFeeOption.function (enum member) FeeOption.Fastest = "fastest"Fastest  // 2x standard

// Usage
await 
Cannot find name 'swapKit'.
swapKit
.transfer({
No value exists in scope for the shorthand property 'assetValue'. Either declare one or provide an initializer.
assetValue
,
No value exists in scope for the shorthand property 'recipient'. Either declare one or provide an initializer.
recipient
,
feeOptionKey: FeeOptionfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast });

SwapKit integrates with multiple swap providers:

import { enum ProviderNameProviderName } from '@swapkit/sdk';

enum ProviderNameProviderName.function (enum member) ProviderName.THORCHAIN = "THORCHAIN"THORCHAIN
enum ProviderNameProviderName.function (enum member) ProviderName.CHAINFLIP = "CHAINFLIP"CHAINFLIP
enum ProviderNameProviderName.function (enum member) ProviderName.ONEINCH = "ONEINCH"ONEINCH
enum ProviderNameProviderName.
Property 'UNISWAP' does not exist on type 'typeof ProviderName'.
UNISWAP
enum ProviderNameProviderName.
Property 'SUSHISWAP' does not exist on type 'typeof ProviderName'. Did you mean 'SUSHISWAP_V2'?
SUSHISWAP
enum ProviderNameProviderName.function (enum member) ProviderName.PANCAKESWAP = "PANCAKESWAP"PANCAKESWAP
// ✅ Good
const const amount: anyamount = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'ETH.ETH', value: numbervalue: 1 });
await
Cannot find name 'swapKit'.
swapKit
.transfer
No value exists in scope for the shorthand property 'recipient'. Either declare one or provide an initializer.
({
assetValue: anyassetValue: const amount: anyamount, recipient });
// ❌ Bad - Don't use raw numbers await
Cannot find name 'swapKit'.
swapKit
No value exists in scope for the shorthand property 'recipient'. Either declare one or provide an initializer.
.
transfer({ value: numbervalue: 1, recipient });
// AssetValue handles decimals automatically
const const usdcAmount: anyusdcAmount = 
Cannot find name 'AssetValue'.
AssetValue
.from({
asset: stringasset: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', value: numbervalue: 100 // This is 100 USDC, not 100 * 10^6 }); // For base units, specify fromBaseDecimal const const weiAmount: anyweiAmount =
Cannot find name 'AssetValue'.
AssetValue
.from({
asset: stringasset: 'ETH.ETH', value: stringvalue: '1000000000000000000', fromBaseDecimal: booleanfromBaseDecimal: true // This is 1 ETH in wei });
// ✅ Good - Use AssetValue comparison methods
if (
Cannot find name 'balance'.
balance
Cannot find name 'requiredAmount'.
.gte(requiredAmount)) {
await
Cannot find name 'performTransaction'.
performTransaction
();
} // ❌ Bad - Don't compare raw values if (
var Number: NumberConstructor
(value?: any) => number
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number
(
Cannot find name 'balance'.
balance
Cannot find name 'requiredAmount'.
.getValue
()) >=
var Number: NumberConstructor
(value?: any) => number
An object that represents a number of any kind. All JavaScript numbers are 64-bit floating-point numbers.
Number
(requiredAmount.getValue())) {
await
Cannot find name 'performTransaction'.
performTransaction
();
}
// Use formatting methods for UI display
const const btcBalance: anybtcBalance = 
Cannot find name 'AssetValue'.
AssetValue
.from({ asset: stringasset: 'BTC.BTC', value: numbervalue: 0.00123456 });
// For display const const displayValue: anydisplayValue = const btcBalance: anybtcBalance.toSignificant(6); // "0.00123456" // For USD value const const usdValue: anyusdValue = const btcBalance: anybtcBalance.toCurrency('USD',
Cannot find name 'btcPrice'.
btcPrice
); // "$55.56"

Now that you understand the core concepts:

  1. Set up your Configuration
  2. Learn about Toolbox Usage for direct chain operations
  3. Start Building Your First App