Connecting Wallets
Connecting Wallets with SwapKit
Section titled “Connecting Wallets with SwapKit”SwapKit provides multiple ways to connect wallets for different blockchain networks. This guide demonstrates how to connect various wallet types using both granular and all-in-one approaches.
Two Approaches to Using SwapKit
Section titled “Two Approaches to Using SwapKit”You can use SwapKit in two ways:
-
Granular approach - Import only what you need from individual packages:
import {
SwapKit } from "@swapkit/core"; 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 ... & { ...; }
keystoreWallet } from "@swapkit/wallets/keystore";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)[]; }; }
-
All-in-one approach - Import everything from the SDK (better for backend/Node.js):
import {
createSwapKit } from "@swapkit/sdk";function createSwapKit(config?: Parameters<typeof SwapKit>[0]): { chainflip: { supportedSwapkitProviders: ProviderName[]; } & { swap: (swapParams: RequestSwapDepositAddressParams) => Promise<...>; }; ... 5 more ...; solana: { ...; } & { ...; }; } & { ...; } & { ...; }
The granular approach is recommended for frontend applications as it results in smaller bundle sizes.
Initialize SwapKit
Section titled “Initialize SwapKit”Granular Approach (Frontend Recommended)
Section titled “Granular Approach (Frontend Recommended)”
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";
import { const ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
}
ledgerWallet } from "@swapkit/wallets/ledger";
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 the SwapKit client with specific wallets
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
connectLedger: (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
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({
config?: SKConfigState | undefined
config: {
apiKeys?: Partial<{
blockchair: string;
kado: string;
keepKey: string;
swapKit: string;
walletConnectProjectId: string;
}> | undefined
apiKeys: {
swapKit?: string | undefined
swapKit: "your-swapkit-api-key",
walletConnectProjectId?: string | undefined
walletConnectProjectId: "your-walletconnect-project-id",
},
},
wallets?: {
connectEVMWallet: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
supportedChains: EVMChain[];
};
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
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, ...const ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
}
ledgerWallet, ...const evmWallet: {
connectEVMWallet: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
supportedChains: EVMChain[];
};
}
evmWallet },
});
All-in-one Approach (Backend/Node.js)
Section titled “All-in-one Approach (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";
// 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({
config?: SKConfigState | undefined
config: {
apiKeys?: Partial<{
blockchair: string;
kado: string;
keepKey: string;
swapKit: string;
walletConnectProjectId: string;
}> | undefined
apiKeys: {
swapKit?: string | undefined
swapKit: "your-swapkit-api-key",
walletConnectProjectId?: string | undefined
walletConnectProjectId: "your-walletconnect-project-id",
},
},
});
Connect with Keystore Wallet
Section titled “Connect with Keystore Wallet”Granular Approach
Section titled “Granular Approach”import { enum Chain
Chain } 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";
import { function decryptFromKeystore(keystore: Keystore, password: string): Promise<string>
decryptFromKeystore, type type Keystore = {
version: number;
meta: string;
crypto: {
cipher: string;
cipherparams: {
iv: string;
};
ciphertext: string;
kdf: string;
kdfparams: {
prf: string;
dklen: number;
salt: string;
c: number;
};
mac: string;
};
}
Keystore } from "@swapkit/wallets/keystore";
// Initialize SwapKit
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 with keystore
async function function connectWithKeystore(keystoreFile: Keystore, password: string, chains: Chain[]): Promise<{
success: boolean;
balances: AssetValue[][];
error?: undefined;
} | {
success: boolean;
error: unknown;
balances?: undefined;
}>
connectWithKeystore(
keystoreFile: Keystore
keystoreFile: type Keystore = {
version: number;
meta: string;
crypto: {
cipher: string;
cipherparams: {
iv: string;
};
ciphertext: string;
kdf: string;
kdfparams: {
prf: string;
dklen: number;
salt: string;
c: number;
};
mac: string;
};
}
Keystore,
password: string
password: string,
chains: Chain[]
chains: enum Chain
Chain[]
) {
try {
// Decrypt the keystore file
const const phrase: string
phrase = await function decryptFromKeystore(keystore: Keystore, password: string): Promise<string>
decryptFromKeystore(keystoreFile: Keystore
keystoreFile, password: string
password);
// Connect the chains with the decrypted phrase
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(chains: Chain[]
chains, const phrase: string
phrase);
// Get wallet balances
const const balances: AssetValue[][]
balances = await var Promise: PromiseConstructor
Represents the completion of an asynchronous operationPromise.PromiseConstructor.all<Promise<AssetValue[]>[]>(values: Promise<AssetValue[]>[]): Promise<AssetValue[][]> (+1 overload)
Creates a Promise that is resolved with an array of results when all of the provided Promises
resolve, or rejected when any Promise is rejected.all(
chains: Chain[]
chains.Array<Chain>.map<Promise<AssetValue[]>>(callbackfn: (value: Chain, index: number, array: Chain[]) => Promise<AssetValue[]>, thisArg?: any): Promise<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(async (chain: Chain
chain) => {
const const wallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
wallet = await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getWalletWithBalance: <Chain>(chain: Chain, scamFilter?: boolean) => Promise<((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}>
getWalletWithBalance(chain: Chain
chain);
return const wallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
wallet.balance: AssetValue[]
balance;
})
);
return { success: boolean
success: true, balances: AssetValue[][]
balances };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
All-in-one Approach
Section titled “All-in-one Approach”
import { enum Chain
Chain } 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";
import { function decryptFromKeystore(keystore: Keystore, password: string): Promise<string>
decryptFromKeystore, type type Keystore = {
version: number;
meta: string;
crypto: {
cipher: string;
cipherparams: {
iv: string;
};
ciphertext: string;
kdf: string;
kdfparams: {
prf: string;
dklen: number;
salt: string;
c: number;
};
mac: string;
};
}
Keystore } from "@swapkit/wallets/keystore";
// Initialize SwapKit
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 with keystore
async function function connectWithKeystore(keystoreFile: Keystore, password: string, chains: Chain[]): Promise<{
success: boolean;
error?: undefined;
} | {
success: boolean;
error: unknown;
}>
connectWithKeystore(
keystoreFile: Keystore
keystoreFile: type Keystore = {
version: number;
meta: string;
crypto: {
cipher: string;
cipherparams: {
iv: string;
};
ciphertext: string;
kdf: string;
kdfparams: {
prf: string;
dklen: number;
salt: string;
c: number;
};
mac: string;
};
}
Keystore,
password: string
password: string,
chains: Chain[]
chains: enum Chain
Chain[]
) {
try {
// Decrypt the keystore file
const const phrase: string
phrase = await function decryptFromKeystore(keystore: Keystore, password: string): Promise<string>
decryptFromKeystore(keystoreFile: Keystore
keystoreFile, password: string
password);
// Connect the chains with the decrypted phrase
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(chains: Chain[]
chains, const phrase: string
phrase);
return { success: boolean
success: true };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Using Hardware Wallets
Section titled “Using Hardware Wallets”Ledger Wallet
Section titled “Ledger Wallet”
import { enum Chain
Chain } 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 ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
}
ledgerWallet } from "@swapkit/wallets/ledger";
// Initialize SwapKit with Ledger wallet
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectLedger: (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
} & {
...;
}
swapKit = SwapKit<{
[x: string]: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<...>;
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
wallets?: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
} | undefined
wallets: { ...const ledgerWallet: {
connectLedger: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 12 more ... | Chain.THORChain)[];
};
}
ledgerWallet },
});
// Connect Ledger wallet
async function function connectLedger(chains: Chain[]): Promise<{
success: boolean;
error?: undefined;
} | {
success: boolean;
error: unknown;
}>
connectLedger(chains: Chain[]
chains: enum Chain
Chain[]) {
try {
// Connect to Ledger
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectLedger: (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.connectLedger: (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>
connectLedger(chains: Chain[]
chains);
// Get the wallet address for a specific chain
const const ethAddress: string
ethAddress = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectLedger: (chains: Chain[], derivationPath?: DerivationPathArray | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Ethereum>(chain: Chain.Ethereum) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
return { success: boolean
success: true };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Trezor Wallet
Section titled “Trezor Wallet”
import { enum Chain
Chain, const NetworkDerivationPath: Record<Chain, DerivationPathArray>
NetworkDerivationPath } 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 trezorWallet: {
connectTrezor: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 10 more ... | Chain.Polygon)[];
};
}
trezorWallet } from "@swapkit/wallets/trezor";
// Initialize SwapKit with Trezor wallet
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectTrezor: (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
} & {
...;
}
swapKit = SwapKit<{
[x: string]: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<...>;
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
wallets?: {
connectTrezor: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 10 more ... | Chain.Polygon)[];
};
} | undefined
wallets: { ...const trezorWallet: {
connectTrezor: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 10 more ... | Chain.Polygon)[];
};
}
trezorWallet },
});
// Connect Trezor wallet
async function function connectTrezor(chains: Chain[]): Promise<{
success: boolean;
balance: AssetValue[];
error?: undefined;
} | {
success: boolean;
error: unknown;
balance?: undefined;
}>
connectTrezor(chains: Chain[]
chains: enum Chain
Chain[]) {
try {
// Connect to Trezor
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectTrezor: (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
} & {
...;
}
swapKit.connectTrezor: (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>
connectTrezor([enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin], const NetworkDerivationPath: Record<Chain, DerivationPathArray>
NetworkDerivationPath.type BTC: DerivationPathArray
BTC);
// Get wallet balances for Bitcoin
const const btcWallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
btcWallet = await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectTrezor: (chains: Chain[], derivationPath: DerivationPathArray) => Promise<boolean>;
} & {
...;
}
swapKit.getWalletWithBalance: <Chain.Bitcoin>(chain: Chain.Bitcoin, scamFilter?: boolean) => Promise<((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}>
getWalletWithBalance(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin);
return { success: boolean
success: true, balance: AssetValue[]
balance: const btcWallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
btcWallet.balance: AssetValue[]
balance };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Using Browser Extension Wallets
Section titled “Using Browser Extension Wallets”MetaMask / EVM Wallets
Section titled “MetaMask / EVM Wallets”
import { enum Chain
Chain } 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
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 },
});
// Connect to MetaMask or other EVM wallets
async function function connectEVMWallet(): Promise<{
success: boolean;
address: string;
error?: undefined;
} | {
success: boolean;
error: unknown;
address?: undefined;
}>
connectEVMWallet() {
try {
// This will prompt the user to connect with their browser wallet
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 Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum, enum Chain
Chain.function (enum member) Chain.BinanceSmartChain = "BSC"
BinanceSmartChain]);
// Get the Ethereum address
const const address: string
address = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Ethereum>(chain: Chain.Ethereum) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
return { success: boolean
success: true, address: string
address };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Keplr (Cosmos) Wallet
Section titled “Keplr (Cosmos) Wallet”
import { enum Chain
Chain } 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
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 },
});
// Connect to Keplr
async function function connectKeplr(): Promise<{
success: boolean;
address: string;
error?: undefined;
} | {
success: boolean;
error: unknown;
address?: undefined;
}>
connectKeplr() {
try {
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 Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos]);
// Get the Cosmos address
const const address: string
address = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Cosmos>(chain: Chain.Cosmos) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos);
return { success: boolean
success: true, address: string
address };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Phantom (Solana) Wallet
Section titled “Phantom (Solana) Wallet”
import { enum Chain
Chain } 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 phantomWallet: {
connectPhantom: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[]) => Promise<boolean>;
supportedChains: (Chain.Bitcoin | Chain.Ethereum | Chain.Solana)[];
};
}
phantomWallet } from "@swapkit/wallets/phantom";
// Initialize SwapKit
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectPhantom: (chains: Chain[]) => Promise<boolean>;
} & {
...;
}
swapKit = SwapKit<{
[x: string]: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<...>;
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
wallets?: {
connectPhantom: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[]) => Promise<boolean>;
supportedChains: (Chain.Bitcoin | Chain.Ethereum | Chain.Solana)[];
};
} | undefined
wallets: { ...const phantomWallet: {
connectPhantom: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[]) => Promise<boolean>;
supportedChains: (Chain.Bitcoin | Chain.Ethereum | Chain.Solana)[];
};
}
phantomWallet },
});
// Connect to Phantom
async function function connectPhantom(): Promise<{
success: boolean;
address: string;
error?: undefined;
} | {
success: boolean;
error: unknown;
address?: undefined;
}>
connectPhantom() {
try {
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectPhantom: (chains: Chain[]) => Promise<boolean>;
} & {
...;
}
swapKit.connectPhantom: (chains: Chain[]) => Promise<boolean>
connectPhantom([enum Chain
Chain.function (enum member) Chain.Solana = "SOL"
Solana]);
// Get the Solana address
const const address: string
address = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectPhantom: (chains: Chain[]) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Solana>(chain: Chain.Solana) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Solana = "SOL"
Solana);
return { success: boolean
success: true, address: string
address };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Managing Wallet Connections
Section titled “Managing Wallet Connections”
import { enum Chain
Chain } 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
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 },
});
// Get all connected wallets
function function getAllWallets(): {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
getAllWallets() {
const const wallets: {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
wallets = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAllWallets: () => {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
getAllWallets();
return const wallets: {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
wallets;
}
// Disconnect a specific chain
function function disconnectChain(chain: Chain): void
disconnectChain(chain: Chain
chain: enum Chain
Chain) {
const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.disconnectChain: <Chain>(chain: Chain) => void
disconnectChain(chain: Chain
chain);
}
// Disconnect all wallets
function function disconnectAll(): void
disconnectAll() {
const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.disconnectAll: () => void
disconnectAll();
}
Getting Wallet Balances
Section titled “Getting Wallet Balances”
import { enum Chain
Chain } 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
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 },
});
// Connect a wallet first
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 Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum]);
// Get balance for a specific chain
async function function getChainBalance(chain: Chain): Promise<AssetValue[]>
getChainBalance(chain: Chain
chain: enum Chain
Chain) {
// Get the balance (true parameter refreshes the balance from the network)
const const balance: AssetValue[]
balance = await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getBalance: <Chain, true>(chain: Chain, refresh?: true | undefined) => Promise<AssetValue[]>
getBalance(chain: Chain
chain, true);
return const balance: AssetValue[]
balance;
}
// Get balances for multiple chains
async function function getAllBalances(chains: Chain[]): Promise<({
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
})[]>
getAllBalances(chains: Chain[]
chains: enum Chain
Chain[]) {
const const balances: ({
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
})[]
balances = await var Promise: PromiseConstructor
Represents the completion of an asynchronous operationPromise.PromiseConstructor.all<Promise<{
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
}>[]>(values: Promise<{
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
}>[]): Promise<...> (+1 overload)
Creates a Promise that is resolved with an array of results when all of the provided Promises
resolve, or rejected when any Promise is rejected.all(
chains: Chain[]
chains.Array<Chain>.map<Promise<{
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
}>>(callbackfn: (value: Chain, index: number, array: Chain[]) => Promise<...>, thisArg?: any): Promise<...>[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.map(async (chain: Chain
chain) => {
try {
const const wallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
wallet = await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getWalletWithBalance: <Chain>(chain: Chain, scamFilter?: boolean) => Promise<((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}>
getWalletWithBalance(chain: Chain
chain);
return { chain: Chain
chain, balance: AssetValue[]
balance: const wallet: ((ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
}) | ... 21 more ... | (ChainWallet<...> & {
...;
})) & {
...;
}
wallet.balance: AssetValue[]
balance };
} catch (function (local var) error: unknown
error) {
return { chain: Chain
chain, balance: never[]
balance: [], error: unknown
error };
}
})
);
return const balances: ({
chain: Chain;
balance: AssetValue[];
error?: undefined;
} | {
chain: Chain;
balance: never[];
error: unknown;
})[]
balances;
}
Using WalletConnect
Section titled “Using WalletConnect”
import { enum Chain
Chain } 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 walletconnectWallet: {
connectWalletconnect: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 9 more ... | Chain.THORChain)[];
};
}
walletconnectWallet } from "@swapkit/wallets/walletconnect";
// Initialize SwapKit with WalletConnect
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectWalletconnect: (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
} & {
...;
}
swapKit = SwapKit<{
[x: string]: (pluginParams: SwapKitPluginParams) => {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<...>;
}, {
...;
}>({ config, plugins, wallets, }?: {
...;
}): {
...;
} & ... 1 more ... & {
...;
}
SwapKit({
config?: SKConfigState | undefined
config: {
apiKeys?: Partial<{
blockchair: string;
kado: string;
keepKey: string;
swapKit: string;
walletConnectProjectId: string;
}> | undefined
apiKeys: {
walletConnectProjectId?: string | undefined
walletConnectProjectId: "YOUR_WALLETCONNECT_PROJECT_ID", // Required
},
},
wallets?: {
connectWalletconnect: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 9 more ... | Chain.THORChain)[];
};
} | undefined
wallets: { ...const walletconnectWallet: {
connectWalletconnect: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
supportedChains: (Chain.Arbitrum | ... 9 more ... | Chain.THORChain)[];
};
}
walletconnectWallet },
});
// Connect using WalletConnect
async function function connectWalletConnect(): Promise<{
success: boolean;
error?: undefined;
} | {
success: boolean;
error: unknown;
}>
connectWalletConnect() {
try {
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectWalletconnect: (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.connectWalletconnect: (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>
connectWalletconnect([
enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum,
enum Chain
Chain.function (enum member) Chain.BinanceSmartChain = "BSC"
BinanceSmartChain,
enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos,
]);
// Check connected addresses
const const ethAddress: string
ethAddress = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectWalletconnect: (chains: Chain[], walletconnectOptions?: SignClientTypes.Options | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Ethereum>(chain: Chain.Ethereum) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum);
return { success: boolean
success: true };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}
Advanced: Connecting Multiple Wallets
Section titled “Advanced: Connecting Multiple Wallets”
import { enum Chain
Chain } 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";
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";
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 multiple wallet types
const const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
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?: {
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)[];
};
connectKeplr: {
connectWallet: (connectParams: {
addChain: AddChainType;
}) => (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>;
supportedChains: (Chain.Cosmos | ... 1 more ... | Chain.THORChain)[];
};
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, ...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, ...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 multiple wallet types
async function function connectMultipleWallets(phrase: string): Promise<{
success: boolean;
addresses: {
ETH: string;
GAIA: string;
BTC: string;
};
error?: undefined;
} | {
success: boolean;
error: unknown;
addresses?: undefined;
}>
connectMultipleWallets(phrase: string
phrase: string) {
try {
// Connect EVM wallet for Ethereum
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
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 Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum]);
// Connect Keplr for Cosmos
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | WalletOption.LEAP | undefined) => Promise<boolean>
connectKeplr([enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos]);
// Connect keystore for Bitcoin
await const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | 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 Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin], phrase: string
phrase);
// 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;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
wallets = const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAllWallets: () => {
ARB: ChainWallet<Chain.Arbitrum> & {
estimateTransactionFee: ({ feeOption, chain, ...txObject }: EIP1559TxParams & {
feeOption: FeeOption;
chain: EVMChain;
}) => Promise<...>;
... 20 more ...;
validateAddress: (address: string) => boolean;
};
... 21 more ...;
SOL: ChainWallet<...> & {
...;
};
}
getAllWallets();
// Get addresses for each chain
const const addresses: {
ETH: string;
GAIA: string;
BTC: string;
}
addresses = {
[enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum]: const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Ethereum>(chain: Chain.Ethereum) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Ethereum = "ETH"
Ethereum),
[enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos]: const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Cosmos>(chain: Chain.Cosmos) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Cosmos = "GAIA"
Cosmos),
[enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin]: const swapKit: {
[x: string]: {
supportedSwapkitProviders?: (ProviderName | string)[];
} & Record<string, unknown>;
} & {
connectKeystore: (chains: Chain[], phrase: string, derivationPathMapOrIndex?: number | ... 1 more ... | undefined) => Promise<boolean>;
connectKeplr: (chains: Chain[], walletType?: WalletOption.KEPLR | ... 1 more ... | undefined) => Promise<boolean>;
connectEVMWallet: (chains: Chain[], walletType?: EVMWalletOptions | undefined, eip1193Provider?: Eip1193Provider | undefined) => Promise<boolean>;
} & {
...;
}
swapKit.getAddress: <Chain.Bitcoin>(chain: Chain.Bitcoin) => string
getAddress(enum Chain
Chain.function (enum member) Chain.Bitcoin = "BTC"
Bitcoin),
};
return { success: boolean
success: true, addresses: {
ETH: string;
GAIA: string;
BTC: string;
}
addresses };
} catch (function (local var) error: unknown
error) {
return { success: boolean
success: false, error: unknown
error };
}
}