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

Connecting Wallets

SwapDK 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 SwapDK 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 SwapDK in two ways:

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

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

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

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

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