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

Executing Transactions

SwapKit provides a unified interface for creating and executing transactions across multiple blockchain networks. This guide explains how to perform transactions with the SwapKit library.

You can use SwapKit in two ways:

  1. Granular approach - Import only what you need from individual packages (recommended for frontend):

    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/core";
    import {
    const evmWallet: {
        connectEVMWallet: {
            connectWallet: (connectParams: {
                addChain: AddChainType;
            }) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
            supportedChains: EVMChain[];
        };
    }
    evmWallet
    } from "@swapkit/wallets/evm-extensions";
  2. All-in-one approach - Import everything from the SDK (better for backend/Node.js):

    import { 
    function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
        chainflip: {
            supportedSwapkitProviders: ProviderName[];
        } & {
            swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
        };
        ... 5 more ...;
        solana: {
            ...;
        } & {
            ...;
        };
    } & {
        ...;
    } & {
        ...;
    }
    createSwapKit
    } from "@swapkit/sdk";

The most common transaction is transferring assets from one address to another.


import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
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/core";
import {
const keystoreWallet: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
}
keystoreWallet
} from "@swapkit/wallets/keystore";
// Initialize SwapKit with specific wallets const
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
=
SwapKit<{
    [x: string]: (pluginParams: SwapKitPluginParams) => {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<...>;
}, {
    ...;
}>({ config, plugins, wallets, }?: {
    ...;
}): {
    ...;
} & ... 1 more ... & {
    ...;
}
SwapKit
({
wallets?: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
} | undefined
wallets
: { ...
const keystoreWallet: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
}
keystoreWallet
},
}); // Connect a wallet (required before making transactions) await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
    ARB?: DerivationPathArray | undefined;
    AVAX?: DerivationPathArray | undefined;
    ... 20 more ...;
    SOL?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>
connectKeystore
(
[enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum], "your secret phrase here" ); // Create an AssetValue representing the amount to transfer const const amount: AssetValueamount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Ethereumchain: enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, symbol: stringsymbol: "ETH", value: stringvalue: "0.01", // 0.01 ETH }); // Execute the transaction async function
function transferAsset(): Promise<{
    txHash: any;
    txUrl: string;
}>
transferAsset
() {
try { // Transfer the asset to a recipient const const txHash: anytxHash = await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>transfer({
assetValue: AssetValueassetValue: const amount: AssetValueamount, recipient: stringrecipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", memo?: string | undefinedmemo: "Payment for services", // Optional memo feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast, // Fee speed preference }) // Get explorer URL for the transaction const const txUrl: stringtxUrl =
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.
getExplorerTxUrl: ({ chain, txHash }: {
    txHash: string;
    chain: Chain;
}) => string
getExplorerTxUrl
({
chain: Chainchain: enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, txHash: stringtxHash, }); return { txHash: anytxHash, txUrl: stringtxUrl }; } catch (function (local var) error: unknownerror) { throw function (local var) error: unknownerror; } }

import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
import { 
function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
    chainflip: {
        supportedSwapkitProviders: ProviderName[];
    } & {
        swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
    };
    ... 5 more ...;
    solana: {
        ...;
    } & {
        ...;
    };
} & {
    ...;
} & {
    ...;
}
createSwapKit
} from "@swapkit/sdk";
// Initialize the SwapKit client with all wallets included const
const swapKit: {
    chainflip: {
        supportedSwapkitProviders: ProviderName[];
    } & {
        swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
    };
    ... 5 more ...;
    solana: {
        ...;
    } & {
        ...;
    };
} & {
    ...;
} & {
    ...;
}
swapKit
=
function createSwapKit(config?: Parameters<typeof SwapKit>[0]): {
    chainflip: {
        supportedSwapkitProviders: ProviderName[];
    } & {
        swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
    };
    ... 5 more ...;
    solana: {
        ...;
    } & {
        ...;
    };
} & {
    ...;
} & {
    ...;
}
createSwapKit
();
// Connect a wallet (required before making transactions) await
const swapKit: {
    chainflip: {
        supportedSwapkitProviders: ProviderName[];
    } & {
        swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
    };
    ... 5 more ...;
    solana: {
        ...;
    } & {
        ...;
    };
} & {
    ...;
} & {
    ...;
}
swapKit
.
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
    ARB?: DerivationPathArray | undefined;
    AVAX?: DerivationPathArray | undefined;
    ... 20 more ...;
    SOL?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>
connectKeystore
(
[enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum], "your secret phrase here" ); // Create an AssetValue representing the amount to transfer const const amount: AssetValueamount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Ethereumchain: enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, symbol: stringsymbol: "ETH", value: stringvalue: "0.01", // 0.01 ETH }); // Execute the transaction async function function transferAsset(): Promise<any>transferAsset() { try { const const txHash: anytxHash = await
const swapKit: {
    chainflip: {
        supportedSwapkitProviders: ProviderName[];
    } & {
        swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>;
    };
    ... 5 more ...;
    solana: {
        ...;
    } & {
        ...;
    };
} & {
    ...;
} & {
    ...;
}
swapKit
.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>transfer({
assetValue: AssetValueassetValue: const amount: AssetValueamount, recipient: stringrecipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast, }); return const txHash: anytxHash; } catch (function (local var) error: unknownerror) { throw function (local var) error: unknownerror; } }

import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
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/core";
import {
const evmWallet: {
    connectEVMWallet: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
        supportedChains: EVMChain[];
    };
}
evmWallet
} from "@swapkit/wallets/evm-extensions";
// Initialize SwapKit and connect wallet const
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
=
SwapKit<{
    [x: string]: (pluginParams: SwapKitPluginParams) => {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<...>;
}, {
    ...;
}>({ config, plugins, wallets, }?: {
    ...;
}): {
    ...;
} & ... 1 more ... & {
    ...;
}
SwapKit
({
wallets?: {
    connectEVMWallet: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
        supportedChains: EVMChain[];
    };
} | undefined
wallets
: { ...
const evmWallet: {
    connectEVMWallet: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
        supportedChains: EVMChain[];
    };
}
evmWallet
},
}); await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>connectEVMWallet([enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum]);
// Transfer ERC20 tokens (USDC example) async function function transferERC20(): Promise<any>transferERC20() { // Create an AssetValue for USDC const const usdcAmount: AssetValueusdcAmount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Ethereum;
    symbol: string;
    ticker: string;
    address: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Ethereum;
    symbol: string;
    ticker: string;
    address: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Ethereumchain: enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, symbol: stringsymbol: "USDC", ticker: stringticker: "USDC", address: stringaddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC contract address value: stringvalue: "10", // 10 USDC }); // Transfer USDC const const txHash: anytxHash = await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>transfer({
assetValue: AssetValueassetValue: const usdcAmount: AssetValueusdcAmount, recipient: stringrecipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Average = "average"Average, }); return const txHash: anytxHash; }

import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
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/core";
import {
const keystoreWallet: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
}
keystoreWallet
} from "@swapkit/wallets/keystore";
// Initialize SwapKit and connect wallet const
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
=
SwapKit<{
    [x: string]: (pluginParams: SwapKitPluginParams) => {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<...>;
}, {
    ...;
}>({ config, plugins, wallets, }?: {
    ...;
}): {
    ...;
} & ... 1 more ... & {
    ...;
}
SwapKit
({
wallets?: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
} | undefined
wallets
: { ...
const keystoreWallet: {
    connectKeystore: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
            ARB?: DerivationPathArray | undefined;
            ... 21 more ...;
            SOL?: DerivationPathArray | undefined;
        } | undefined) => Promise<boolean>;
        supportedChains: (Chain.Arbitrum | ... 18 more ... | Chain.Solana)[];
    };
}
keystoreWallet
},
}); await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | {
    ARB?: DerivationPathArray | undefined;
    AVAX?: DerivationPathArray | undefined;
    ... 20 more ...;
    SOL?: DerivationPathArray | undefined;
} | undefined) => Promise<boolean>
connectKeystore
([enum ChainChain.function (enum member) Chain.Bitcoin = "BTC"Bitcoin], "your secret phrase here");
// Transfer Bitcoin async function function transferBitcoin(): Promise<any>transferBitcoin() { // Create an AssetValue for Bitcoin const const btcAmount: AssetValuebtcAmount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Bitcoin;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Bitcoin;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Bitcoinchain: enum ChainChain.function (enum member) Chain.Bitcoin = "BTC"Bitcoin, symbol: stringsymbol: "BTC", value: stringvalue: "0.001", // 0.001 BTC }); // Transfer BTC const const txHash: anytxHash = await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>transfer({
assetValue: AssetValueassetValue: const btcAmount: AssetValuebtcAmount, recipient: stringrecipient: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq", feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast, memo?: string | undefinedmemo: "Bitcoin transfer example", }); return const txHash: anytxHash; }

import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
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/core";
import {
const keplrWallet: {
    connectKeplr: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>;
        supportedChains: (Chain.Cosmos | ... 1 more ... | Chain.THORChain)[];
    };
}
keplrWallet
} from "@swapkit/wallets/keplr";
// Initialize SwapKit and connect wallet const
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
=
SwapKit<{
    [x: string]: (pluginParams: SwapKitPluginParams) => {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<...>;
}, {
    ...;
}>({ config, plugins, wallets, }?: {
    ...;
}): {
    ...;
} & ... 1 more ... & {
    ...;
}
SwapKit
({
wallets?: {
    connectKeplr: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>;
        supportedChains: (Chain.Cosmos | ... 1 more ... | Chain.THORChain)[];
    };
} | undefined
wallets
: { ...
const keplrWallet: {
    connectKeplr: {
        connectWallet: (connectParams: {
            addChain: AddChainType;
        }) => (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>;
        supportedChains: (Chain.Cosmos | ... 1 more ... | Chain.THORChain)[];
    };
}
keplrWallet
},
}); await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>connectKeplr([enum ChainChain.function (enum member) Chain.Cosmos = "GAIA"Cosmos]);
// Transfer Cosmos assets async function function transferCosmos(): Promise<any>transferCosmos() { // Create an AssetValue for ATOM const const atomAmount: AssetValueatomAmount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Cosmos;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Cosmos;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Cosmoschain: enum ChainChain.function (enum member) Chain.Cosmos = "GAIA"Cosmos, symbol: stringsymbol: "ATOM", value: stringvalue: "0.1", // 0.1 ATOM }); // Transfer ATOM const const txHash: anytxHash = await
const swapKit: {
    [x: string]: {
        supportedSwapkitProviders?: (ProviderName | string)[];
    } & Record<string, unknown>;
} & {
    connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
} & {
    ...;
}
swapKit
.transfer: ({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) => Promise<any>transfer({
assetValue: AssetValueassetValue: const atomAmount: AssetValueatomAmount, recipient: stringrecipient: "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12", feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Average = "average"Average, memo?: string | undefinedmemo: "Cosmos transfer example", }); return const txHash: anytxHash; }

For lower-level control, you can use the toolboxes directly instead of SwapKit’s high-level API:


import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
import { function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>getProvider, 
function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}>
getEvmToolbox
} from "@swapkit/toolboxes/evm";
import { import ethersethers } from "ethers"; async function function directEVMTransfer(): Promise<string>directEVMTransfer() { // Create a signer const const provider: ethers.JsonRpcProviderprovider = await function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>getProvider(enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum); const const signer: ethers.Walletsigner = new import ethersethers.
new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected to %%provider%%.
Wallet
("your-private-key-here", const provider: ethers.JsonRpcProviderprovider);
// Create a toolbox with the signer const
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<AssetValue>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
= await
getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}>
getEvmToolbox
(enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, { signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefinedsigner });
// Create an asset value const const amount: AssetValueamount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Ethereum;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Ethereumchain: enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, symbol: stringsymbol: "ETH", value: stringvalue: "0.01", }); // Transfer ETH const const txHash: stringtxHash = await
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<AssetValue>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
.transfer: ({ assetValue, memo, recipient, feeOptionKey, sender, ...tx }: EVMTransferParams) => Promise<string>transfer({
assetValue: AssetValueassetValue: const amount: AssetValueamount, recipient: stringrecipient: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", from: const signer: ethers.Walletsigner.BaseWallet.address: string
The wallet address.
address
,
Object literal may only specify known properties, and 'from' does not exist in type 'EVMTransferParams'.
feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast, }); return const txHash: stringtxHash; }

import { class AssetValueAssetValue, enum ChainChain, enum FeeOptionFeeOption } from "@swapkit/helpers";
import { 
function getUtxoToolbox<T extends keyof UTXOToolboxes>(chain: T, params?: UtxoToolboxParams[T] | {
    phrase?: string;
    derivationPath?: DerivationPathArray;
    index?: number;
}): Promise<UTXOToolboxes[T]>
getUtxoToolbox
} from "@swapkit/toolboxes/utxo";
async function function directBitcoinTransfer(): Promise<string>directBitcoinTransfer() { const
const btcToolbox: {
    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
= await
getUtxoToolbox<Chain.Bitcoin>(chain: Chain.Bitcoin, params?: {
    phrase?: string;
    derivationPath?: DerivationPathArray;
    index?: number;
} | {
    signer: ChainSigner<Psbt, Psbt>;
} | undefined): Promise<...>
getUtxoToolbox
(enum ChainChain.function (enum member) Chain.Bitcoin = "BTC"Bitcoin);
// Generate keys from a mnemonic phrase const const keys: ECPairInterfacekeys = await
const btcToolbox: {
    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
.
createKeysForPath: (params: {
    wif?: string;
    phrase?: string;
    derivationPath?: string;
}) => ECPairInterface
createKeysForPath
({
phrase?: string | undefinedphrase: "your twelve word mnemonic phrase here", derivationPath?: string | undefinedderivationPath: "m/84'/0'/0'/0/0", }); const const fromAddress: stringfromAddress =
const btcToolbox: {
    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
.getAddressFromKeys: (keys: ECPairInterface | BchECPair) => stringgetAddressFromKeys(const keys: ECPairInterfacekeys);
// Create a function to sign transactions async function
function (local function) signTransaction({ builder, utxos }: {
    builder: any;
    utxos: any[];
}): Promise<any>
signTransaction
({ builder: anybuilder, utxos: any[]utxos }: { builder: anybuilder: any, utxos: any[]utxos: any[] }) {
utxos: any[]utxos.Array<any>.forEach(callbackfn: (value: any, index: number, array: any[]) => void, thisArg?: any): void
Performs the specified action for each element in an array.
@paramcallbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
forEach
((utxo: anyutxo, index: numberindex) => {
builder: anybuilder.sign(index: numberindex, const keys: ECPairInterfacekeys); }); return builder: anybuilder.build(); } // Create an asset value const const amount: AssetValueamount = class AssetValueAssetValue.
AssetValue.from<{
    chain: Chain.Bitcoin;
    symbol: string;
    value: string;
}>({ value, fromBaseDecimal, asyncTokenLookup, ...fromAssetOrChain }: {
    chain: Chain.Bitcoin;
    symbol: string;
    value: string;
} & AssetValueFromParams): AssetValue
from
({
chain: Chain.Bitcoinchain: enum ChainChain.function (enum member) Chain.Bitcoin = "BTC"Bitcoin, symbol: stringsymbol: "BTC", value: stringvalue: "0.001", }); // Transfer BTC const const txHash: stringtxHash = await
const btcToolbox: {
    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
.transfer: ({ memo, recipient, feeOptionKey, feeRate, assetValue, }: UTXOTransferParams) => Promise<string>transfer({
assetValue: AssetValueassetValue: const amount: AssetValueamount, recipient: stringrecipient: "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq", from: const fromAddress: stringfromAddress,
Object literal may only specify known properties, and 'from' does not exist in type 'GenericTransferParams'.
feeOptionKey?: FeeOption | undefinedfeeOptionKey: enum FeeOptionFeeOption.function (enum member) FeeOption.Fast = "fast"Fast, // @ts-ignore - it should return PSBT and it's usually using psbt to sign tx
signTransaction: ({ builder, utxos }: {
    builder: any;
    utxos: any[];
}) => Promise<any>
signTransaction
,
}); return const txHash: stringtxHash; }

For EVM chains, you can interact with smart contracts using the EVM toolbox:


import { enum ChainChain } from "@swapkit/helpers";
import { 
function getEvmToolbox<T extends EVMChain>(chain: T, params?: EVMToolboxParams): Promise<{
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}>
getEvmToolbox
, function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>getProvider } from "@swapkit/toolboxes/evm";
import { import ethersethers } from "ethers"; import {
const erc20ABI: ({
    inputs: never[];
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    stateMutability?: undefined;
    outputs?: undefined;
} | {
    ...;
})[]
erc20ABI
} from "@swapkit/helpers/contracts";
async function
function interactWithContract(): Promise<{
    name: unknown;
    symbol: unknown;
    decimals: number;
    balance: string;
}>
interactWithContract
() {
// Create a provider and signer const const provider: ethers.JsonRpcProviderprovider = await function getProvider(chain: EVMChain, customUrl?: string): Promise<ethers.JsonRpcProvider>getProvider(enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum); const const signer: ethers.Walletsigner = new import ethersethers.
new Wallet(key: string | ethers.SigningKey, provider?: null | ethers.Provider): ethers.Wallet
export Wallet
Create a new wallet for the private %%key%%, optionally connected to %%provider%%.
Wallet
("your-private-key-here", const provider: ethers.JsonRpcProviderprovider);
// Get the EVM toolbox const
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
= await
getEvmToolbox<Chain.Ethereum>(chain: Chain.Ethereum, params?: EVMToolboxParams): Promise<{
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}>
getEvmToolbox
(enum ChainChain.function (enum member) Chain.Ethereum = "ETH"Ethereum, {signer?: (ChainSigner<EVMTransferParams, string> & ethers.Signer) | ethers.JsonRpcSigner | undefinedsigner });
// USDC contract address const const contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"contractAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // Get token details const const tokenName: unknowntokenName = await
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
.call: <unknown>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<unknown>
@infocall contract function When using this method to make a non state changing call to the blockchain, like a isApproved call, the signer needs to be set to undefined
call
({
contractAddress: stringcontractAddress, abi: readonly ethers.JsonFragment[]abi:
const erc20ABI: ({
    inputs: never[];
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    stateMutability?: undefined;
    outputs?: undefined;
} | {
    ...;
})[]
erc20ABI
,
funcName: stringfuncName: "name", }); const const tokenSymbol: unknowntokenSymbol = await
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
.call: <unknown>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<unknown>
@infocall contract function When using this method to make a non state changing call to the blockchain, like a isApproved call, the signer needs to be set to undefined
call
({
contractAddress: stringcontractAddress, abi: readonly ethers.JsonFragment[]abi:
const erc20ABI: ({
    inputs: never[];
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    stateMutability?: undefined;
    outputs?: undefined;
} | {
    ...;
})[]
erc20ABI
,
funcName: stringfuncName: "symbol", }); const const tokenDecimals: numbertokenDecimals = await
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
.call: <number>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<number>
@infocall contract function When using this method to make a non state changing call to the blockchain, like a isApproved call, the signer needs to be set to undefined
call
<number>({
contractAddress: stringcontractAddress, abi: readonly ethers.JsonFragment[]abi:
const erc20ABI: ({
    inputs: never[];
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    stateMutability?: undefined;
    outputs?: undefined;
} | {
    ...;
})[]
erc20ABI
,
funcName: stringfuncName: "decimals", }); // Get balance const const balance: stringbalance = await
const ethToolbox: {
    estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
        feeOption: FeeOption;
        chain: EVMChain;
    }) => Promise<...>;
    ... 20 more ...;
    validateAddress: (address: string) => boolean;
} | {
    ...;
} | {
    ...;
}
ethToolbox
.call: <string>({ callProvider, contractAddress, abi, funcName, funcParams, txOverrides, feeOption, }: CallParams) => Promise<string>
@infocall contract function When using this method to make a non state changing call to the blockchain, like a isApproved call, the signer needs to be set to undefined
call
<string>({
contractAddress: stringcontractAddress, abi: readonly ethers.JsonFragment[]abi:
const erc20ABI: ({
    inputs: never[];
    stateMutability: string;
    type: string;
    anonymous?: undefined;
    name?: undefined;
    outputs?: undefined;
} | {
    anonymous: boolean;
    inputs: {
        indexed: boolean;
        internalType: string;
        name: string;
        type: string;
    }[];
    name: string;
    type: string;
    stateMutability?: undefined;
    outputs?: undefined;
} | {
    ...;
})[]
erc20ABI
,
funcName: stringfuncName: "balanceOf", funcParams?: unknown[] | undefinedfuncParams: [const signer: ethers.Walletsigner.BaseWallet.address: string
The wallet address.
address
],
}); // Format the balance using decimals const const formattedBalance: stringformattedBalance = import ethersethers.
function formatUnits(value: ethers.BigNumberish, unit?: string | ethers.Numeric): string
export formatUnits
Converts %%value%% into a //decimal string//, assuming %%unit%% decimal places. The %%unit%% may be the number of decimal places or the name of a unit (e.g. ``"gwei"`` for 9 decimal places).
formatUnits
(const balance: stringbalance, const tokenDecimals: numbertokenDecimals);
return { name: unknownname: const tokenName: unknowntokenName, symbol: unknownsymbol: const tokenSymbol: unknowntokenSymbol, decimals: numberdecimals: const tokenDecimals: numbertokenDecimals, balance: stringbalance: const formattedBalance: stringformattedBalance, }; }