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 â
 Try it live in StackBlitz â
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, keystoreWallet } from "@swapkit/sdk"; - 
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.
Initialize SwapKit
Section titled âInitialize SwapKitâGranular Approach (Frontend Recommended)
Section titled âGranular Approach (Frontend Recommended)â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 },});All-in-one Approach (Backend/Node.js)
Section titled âAll-in-one Approach (Backend/Node.js)âimport { createSwapKit } from "@swapkit/sdk";
const swapKit = createSwapKit({  config: {    apiKeys: {      swapKit: "your-swapkit-api-key",      walletConnectProjectId: "your-walletconnect-project-id",    },  },});Connect with Keystore Wallet
Section titled âConnect with Keystore WalletâGranular Approach
Section titled âGranular Approachâ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);All-in-one Approach
Section titled âAll-in-one Approachâ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 };  }}Using Hardware Wallets
Section titled âUsing Hardware WalletsâLedger Wallet
Section titled âLedger Walletâ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 };  }}Trezor Wallet
Section titled âTrezor Walletâ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 };  }}Using Browser Extension Wallets
Section titled âUsing Browser Extension WalletsâMetaMask / EVM Wallets
Section titled âMetaMask / EVM Walletsâ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 };  }}Keplr (Cosmos) Wallet
Section titled âKeplr (Cosmos) Walletâ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 };  }}Cosmostation (Cosmos) Wallet
Section titled âCosmostation (Cosmos) Walletâ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 };  }}Phantom (Solana) Wallet
Section titled âPhantom (Solana) Walletâ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 };  }}Managing Wallet Connections
Section titled âManaging Wallet Connectionsâ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();}Getting Wallet Balances
Section titled âGetting Wallet Balancesâ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;}Using WalletConnect
Section titled âUsing WalletConnectâ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 };  }}Advanced: Connecting Multiple Wallets
Section titled âAdvanced: Connecting Multiple Walletsâ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 };  }}