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

Connecting Wallets

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.

Wallet Connection Demo

Try connecting different wallet types to see how SwapKit handles multi-chain connections

Connection Status Disconnected
Select chains and a wallet type, then click "Connect Wallet" to see the connection process.
Note: This is a simulation for demonstration purposes. In a real application, you'd handle actual wallet connections and user interactions.
Try it live in StackBlitz →

You can use SwapKit in two ways:

  1. Granular approach - Import only what you need from individual packages:

    import { SwapKit, keystoreWallet } from "@swapkit/sdk";
  2. All-in-one approach - Import everything from the SDK (better for backend/Node.js):

    import { createSwapKit } from "@swapkit/sdk";

The granular approach is recommended for frontend applications as it results in smaller bundle sizes.

import { SwapKit, keystoreWallet, ledgerWallet, evmWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
config: {
apiKeys: {
swapKit: "your-swapkit-api-key",
walletConnectProjectId: "your-walletconnect-project-id",
},
},
wallets: { ...keystoreWallet, ...ledgerWallet, ...evmWallet },
});
import { createSwapKit } from "@swapkit/sdk";
const swapKit = createSwapKit({
config: {
apiKeys: {
swapKit: "your-swapkit-api-key",
walletConnectProjectId: "your-walletconnect-project-id",
},
},
});
import {
Chain,
SwapKit,
keystoreWallet,
decryptFromKeystore,
type Keystore,
} from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...keystoreWallet },
});
async function connectWithKeystore(
keystoreFile: Keystore,
password: string,
chains: Chain[]
) {
try {
const phrase = await decryptFromKeystore(keystoreFile, password);
await swapKit.connectKeystore(chains, phrase);
const balances = await Promise.all(
chains.map(async (chain) => {
const wallet = await swapKit.getWalletWithBalance(chain);
return wallet.balance;
})
);
return { success: true, balances };
} catch (error) {
return { success: false, error };
}
}
const chains = [Chain.Ethereum, Chain.Bitcoin, Chain.Ripple];
await connectWithKeystore(keystoreFile, password, chains);
import {
Chain,
createSwapKit,
decryptFromKeystore,
type Keystore,
} from "@swapkit/sdk";
const swapKit = createSwapKit();
async function connectWithKeystore(
keystoreFile: Keystore,
password: string,
chains: Chain[]
) {
try {
const phrase = await decryptFromKeystore(keystoreFile, password);
await swapKit.connectKeystore(chains, phrase);
return { success: true };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, ledgerWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...ledgerWallet },
});
async function connectLedger(chains: Chain[]) {
try {
await swapKit.connectLedger(chains);
const ethAddress = swapKit.getAddress(Chain.Ethereum);
return { success: true };
} catch (error) {
return { success: false, error };
}
}
import {
Chain,
NetworkDerivationPath,
SwapKit,
trezorWallet,
} from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...trezorWallet },
});
async function connectTrezor(chains: Chain[]) {
try {
await swapKit.connectTrezor([Chain.Bitcoin], NetworkDerivationPath.BTC);
const btcWallet = await swapKit.getWalletWithBalance(Chain.Bitcoin);
return { success: true, balance: btcWallet.balance };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, evmWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...evmWallet },
});
async function connectEVMWallet() {
try {
await swapKit.connectEVMWallet([Chain.Ethereum, Chain.BinanceSmartChain]);
const address = swapKit.getAddress(Chain.Ethereum);
return { success: true, address };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, keplrWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...keplrWallet },
});
async function connectKeplr() {
try {
await swapKit.connectKeplr([Chain.Cosmos]);
const address = swapKit.getAddress(Chain.Cosmos);
return { success: true, address };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, cosmostationWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...cosmostationWallet },
});
async function connectCosmostation() {
try {
await swapKit.connectCosmostation([Chain.Cosmos, Chain.THORChain]);
const address = swapKit.getAddress(Chain.Cosmos);
return { success: true, address };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, phantomWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...phantomWallet },
});
async function connectPhantom() {
try {
await swapKit.connectPhantom([Chain.Solana]);
const address = swapKit.getAddress(Chain.Solana);
return { success: true, address };
} catch (error) {
return { success: false, error };
}
}
import { Chain, SwapKit, evmWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...evmWallet },
});
function getAllWallets() {
const wallets = swapKit.getAllWallets();
return wallets;
}
function disconnectChain(chain: Chain) {
swapKit.disconnectChain(chain);
}
function disconnectAll() {
swapKit.disconnectAll();
}
import { Chain, SwapKit, evmWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...evmWallet },
});
await swapKit.connectEVMWallet([Chain.Ethereum]);
async function getChainBalance(chain: Chain) {
const balance = await swapKit.getBalance(chain, true);
return balance;
}
async function getAllBalances(chains: Chain[]) {
const balances = await Promise.all(
chains.map(async (chain) => {
try {
const wallet = await swapKit.getWalletWithBalance(chain);
return { chain, balance: wallet.balance };
} catch (error) {
return { chain, balance: [], error };
}
})
);
return balances;
}
import { Chain, SwapKit, walletconnectWallet } from "@swapkit/sdk";
const swapKit = SwapKit({
config: {
apiKeys: {
walletConnectProjectId: "YOUR_WALLETCONNECT_PROJECT_ID",
},
},
wallets: { ...walletconnectWallet },
});
async function connectWalletConnect() {
try {
await swapKit.connectWalletconnect([
Chain.Ethereum,
Chain.BinanceSmartChain,
Chain.Cosmos,
]);
const ethAddress = swapKit.getAddress(Chain.Ethereum);
return { success: true };
} catch (error) {
return { success: false, error };
}
}
import {
Chain,
SwapKit,
evmWallet,
keplrWallet,
keystoreWallet,
} from "@swapkit/sdk";
const swapKit = SwapKit({
wallets: { ...evmWallet, ...keplrWallet, ...keystoreWallet },
});
async function connectMultipleWallets(phrase: string) {
try {
await swapKit.connectEVMWallet([Chain.Ethereum]);
await swapKit.connectKeplr([Chain.Cosmos]);
await swapKit.connectKeystore([Chain.Bitcoin], phrase);
const wallets = swapKit.getAllWallets();
const addresses = {
[Chain.Ethereum]: swapKit.getAddress(Chain.Ethereum),
[Chain.Cosmos]: swapKit.getAddress(Chain.Cosmos),
[Chain.Bitcoin]: swapKit.getAddress(Chain.Bitcoin),
};
return { success: true, addresses };
} catch (error) {
return { success: false, error };
}
}