### Basic setup with SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/near-integration.mdx Create a SwapKit instance and get a NEAR wallet. ```typescript // @noErrorValidation import { createSwapKit } from '@swapkit/sdk'; const swapKit = createSwapKit(); const nearWallet = await swapKit.getWallet(Chain.Near); ``` -------------------------------- ### Basic Setup with SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/dogecoin.mdx Create a SwapKit instance and get a Dogecoin wallet. This is the recommended approach for most integrations. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const dogeWallet = await swapKit.getWallet(Chain.Dogecoin); ``` -------------------------------- ### Basic Setup with SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/avalanche.mdx Create a SwapKit instance and get an Avalanche wallet using the Chain.Avalanche enum. This is the recommended approach for most integrations. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const avaxWallet = await swapKit.getWallet(Chain.Avalanche); ``` -------------------------------- ### Import and Initialize SwapKit Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/getting-started.mdx Import and initialize SwapKit with default settings. This is the minimal setup required to start using the SDK. ```typescript // @noErrorValidation import { createSwapKit } from "@swapkit/sdk"; const swapKit = createSwapKit(); ``` -------------------------------- ### Basic Setup with SwapKit SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/tron.mdx Initialize SwapKit and get a Tron wallet using the Chain.Tron enum. This snippet is from the 'With SDK' tab. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapKit/sdk'; const swapKit = createSwapKit(); const tronWallet = await swapKit.getWallet(Chain.Tron); ``` -------------------------------- ### XRP Cross-Chain Swap and Arbitrage Example Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/xrp.mdx Demonstrates getting a quote for swapping XRP to BTC, executing the swap with a fast fee option, getting a quote for XRP to USDC, and checking for an arbitrage opportunity by comparing the native XRP order book with an external price. The example uses the SwapKit SDK and assumes the necessary setup is already in place. ```typescript // @noErrorValidation const xrpToBtcQuote = await swapKit.getQuote({ sellAsset: "XRP.XRP", sellAmount: "1000", buyAsset: "BTC.BTC", senderAddress: swapKit.getAddress(Chain.Ripple), recipientAddress: swapKit.getAddress(Chain.Bitcoin), }); console.log("XRP -> BTC quote:", { expectedOutput: xrpToBtcQuote.expectedOutput, fees: xrpToBtcQuote.fees, timeEstimate: xrpToBtcQuote.timeEstimate, }); const swapTx = await swapKit.swap({ route: xrpToBtcQuote.routes[0], feeOptionKey: FeeOption.Fast, }); const xrpToUsdcQuote = await swapKit.getQuote({ sellAsset: "XRP.XRP", sellAmount: "500", buyAsset: "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", senderAddress: swapKit.getAddress(Chain.Ripple), recipientAddress: swapKit.getAddress(Chain.Ethereum), }); const arbitrageOpportunity = async () => { const orderBooks = await Promise.all([ xrpToolbox.getOrderBook({ takerGets: { currency: "XRP" }, takerPays: { currency: "USD", issuer: "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", }, }), getExternalXRPPrice(), ]); const [nativeBook, externalPrice] = orderBooks; const bestAsk = parseFloat(nativeBook.asks[0]?.TakerPays?.value || "0"); if (bestAsk > 0 && externalPrice > bestAsk * 1.02) { console.log( `Arbitrage opportunity: ${( ((externalPrice - bestAsk) / bestAsk) * 100 ).toFixed(2)}%` ); } }; ``` -------------------------------- ### Install Bun Source: https://github.com/swapkit/swapkit/blob/develop/README.md Installs the Bun runtime using the official installation script. Run this before bootstrapping the project. ```bash curl -fsSL https://bun.sh/install | bash ``` -------------------------------- ### Install and Initialize SwapKit Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/getting-started.mdx Installs the SDK and creates a SwapKit instance with an optional API key. The API key is for enhanced features; the SDK works without it for basic functionality. ```bash bun add @swapkit/sdk ``` ```typescript import { createSwapKit } from '@swapkit/sdk'; const swapKit = createSwapKit({ config: { apiKeys: { swapKit: 'your-api-key-here' } } }); ``` -------------------------------- ### Granular Setup with SwapKit and evmWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/browser-extensions/metamask.mdx Use this setup for frontend applications. It imports SwapKit, evmWallet, Chain, and WalletOption from @swapkit/sdk, and initializes SwapKit with an API key and the evmWallet. ```ts import { SwapKit, evmWallet, Chain, WalletOption } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...evmWallet }, }); ``` -------------------------------- ### Install SwapKit packages Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/litecoin.mdx Install the full SwapKit SDK or individual packages for smaller bundles. ```bash bun add @swapkit/sdk ``` ```bash bun add @swapkit/toolboxes @swapkit/plugins ``` -------------------------------- ### Install SwapKit SDK with Bun Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit SDK using the Bun package manager. ```bash bun add @swapkit/sdk ``` -------------------------------- ### Bootstrap project with Bun Source: https://github.com/swapkit/swapkit/blob/develop/README.md Installs project dependencies and prepares the repository for development. Run after installing Bun. ```bash bun bootstrap ``` -------------------------------- ### Complete SwapKit configuration example with SKConfig.set() Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/api-reference.mdx Complete example of configuring SwapKit with environment variables, including API keys, RPC URLs, Midgard URLs, API headers, and environment flags. Also shows how to enable stagenet mode conditionally. ```typescript // @noErrorValidation import { SKConfig, Chain, StagenetChain } from '@swapkit/sdk'; SKConfig.set({ apiKeys: { swapKit: process.env.SWAPKIT_API_KEY, blockchair: process.env.BLOCKCHAIR_API_KEY }, rpcUrls: { [Chain.Ethereum]: 'https: [Chain.Polygon]: 'https: }, midgardUrls: { [Chain.THORChain]: 'https: [StagenetChain.THORChain]: 'https: }, apiHeaders: { midgard: { 'X-Client-ID': process.env.CLIENT_ID }, thornode: { 'X-Client-ID': process.env.CLIENT_ID } }, envs: { isDev: process.env.NODE_ENV === 'development', isStagenet: false } }); if (userPrefersTestnet) { SKConfig.setEnv('isStagenet', true); } ``` -------------------------------- ### Install SwapKit and node-polyfill-webpack-plugin with npm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/nextjs.mdx Use npm to install the SwapKit SDK and the node-polyfill-webpack-plugin package. ```bash npm install @swapkit/sdk node-polyfill-webpack-plugin ``` -------------------------------- ### Install SwapKit SDK with npm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit SDK using the npm package manager. ```bash npm install @swapkit/sdk ``` -------------------------------- ### Install SwapKit SDK with Yarn Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit SDK using the Yarn package manager. ```bash yarn add @swapkit/sdk ``` -------------------------------- ### Install SwapKit SDK with pnpm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit SDK using the pnpm package manager. ```bash pnpm add @swapkit/sdk ``` -------------------------------- ### Install SwapKit Core with Bun Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit Core package using the Bun package manager. ```bash bun add @swapkit/core ``` -------------------------------- ### Install @swapkit/sdk with bun, pnpm, npm, yarn, or expo Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/react-native.mdx Install SwapKit and its dependencies using your preferred package manager. The commands are shown in tabs for bun, pnpm, npm, yarn, and expo. ```bash bun add @swapkit/sdk ``` ```bash pnpm add @swapkit/sdk ``` ```bash npm install @swapkit/sdk ``` ```bash yarn add @swapkit/sdk ``` ```bash expo install @swapkit/sdk ``` -------------------------------- ### Install SwapKit and vite-plugin-node-polyfills Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/vite.mdx Install SwapKit and the required vite-plugin-node-polyfills dependency using your preferred package manager. ```bash bun add @swapkit/sdk vite-plugin-node-polyfills ``` ```bash pnpm add @swapkit/sdk vite-plugin-node-polyfills ``` ```bash npm install @swapkit/sdk vite-plugin-node-polyfills ``` ```bash yarn add @swapkit/sdk vite-plugin-node-polyfills ``` -------------------------------- ### Get Optimism Wallet with SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/optimism.mdx Initialize SwapKit and get an Optimism wallet using the SDK. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const opWallet = await swapKit.getWallet(Chain.Optimism); ``` -------------------------------- ### Install Wallets Component with Bun Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the wallets component package using the Bun package manager. ```bash bun add @swapkit/wallets ``` -------------------------------- ### Get Maya Wallet with SwapKit SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/maya.mdx Initialize SwapKit and get a Maya wallet using the SDK. This is the recommended approach for most integrations. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const mayaWallet = await swapKit.getWallet(Chain.Maya); ``` -------------------------------- ### Get Solana Wallet with SwapKit SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/solana.mdx Initialize SwapKit and get a Solana wallet instance using the SDK. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const solWallet = await swapKit.getWallet(Chain.Solana); ``` -------------------------------- ### Install Plugins Component with Bun Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the plugins component package using the Bun package manager. ```bash bun add @swapkit/plugins ``` -------------------------------- ### Get Cosmos Wallet with SwapKit SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/cosmos.mdx Initialize SwapKit and get a Cosmos wallet instance using the SDK. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const cosmosWallet = await swapKit.getWallet(Chain.Cosmos); ``` -------------------------------- ### Install SwapKit Core with npm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit Core package using the npm package manager. ```bash npm install @swapkit/core ``` -------------------------------- ### Install SwapKit Core with Yarn Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit Core package using the Yarn package manager. ```bash yarn add @swapkit/core ``` -------------------------------- ### Install SwapKit Core with pnpm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the SwapKit Core package using the pnpm package manager. ```bash pnpm add @swapkit/core ``` -------------------------------- ### Install Wallets Component with npm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/getting-started.mdx Install the wallets component package using the npm package manager. ```bash npm install @swapkit/wallets ``` -------------------------------- ### Get Bitcoin Cash Wallet with SDK Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/bitcoin-cash.mdx Initialize SwapKit and get a Bitcoin Cash wallet using the SDK. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const bchWallet = await swapKit.getWallet(Chain.BitcoinCash); ``` -------------------------------- ### Install SwapKit with bun, pnpm, npm, or yarn Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/bun.mdx Install SwapKit using your preferred package manager. The bun command is the primary option for Bun projects, while pnpm, npm, and yarn are alternatives. ```bash bun add @swapkit/sdk ``` ```bash pnpm add @swapkit/sdk ``` ```bash npm install @swapkit/sdk ``` ```bash yarn add @swapkit/sdk ``` -------------------------------- ### Install Required Ledger Apps Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/ledger.mdx Lists the Ledger Live apps to install for each supported chain group before using SwapKit with a Ledger device. ```bash # For Bitcoin transactions - Bitcoin app # For Ethereum and EVM chains - Ethereum app # For Cosmos and THORChain - Cosmos app - THORChain app (if available) # For other specific chains - Near app - Ripple (XRP) app - Tron app ``` -------------------------------- ### Basic Setup: Granular Approach (Frontend) Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/browser-extensions/okx.mdx Recommended for frontend applications. Imports and initializes SwapKit with the OKX wallet and a SwapKit API key. ```ts import { SwapKit, okxWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...okxWallet }, }); ``` -------------------------------- ### Get PancakeSwap Quote for BNB to USDT Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/bsc.mdx Get a quote from PancakeSwap for swapping BNB to USDT on BSC. The example specifies the provider as PANCAKESWAP and uses the swapKit instance to obtain addresses. ```typescript const pancakeQuote = await swapKit.getQuote({ sellAsset: "BSC.BNB", sellAmount: "10", buyAsset: "BSC.USDT-0x55d398326f99059fF775485246999027B3197955", senderAddress: swapKit.getAddress(Chain.BinanceSmartChain), recipientAddress: swapKit.getAddress(Chain.BinanceSmartChain), providers: ["PANCAKESWAP"], }); ``` -------------------------------- ### Use Native SegWit Addresses Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/litecoin.mdx Shows example Litecoin addresses: a native SegWit address (starting with 'ltc1') and a legacy address (starting with 'L'). Use native SegWit addresses for lower fees and better performance. ```typescript const recipient = "ltc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"; const legacy = "LdP8Qox1VAhCzLJNqrr74YovaWYyNBUWvL"; ``` -------------------------------- ### Using Core + Plugins (Modular Approach) Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/getting-started.mdx Import SwapKit, ThorchainPlugin, keystoreWallet, and ledgerWallet from @swapkit/sdk. Initialize SwapKit with the plugin and wallets to reduce bundle size. ```typescript // @noErrorValidation import { SwapKit, ThorchainPlugin, keystoreWallet, ledgerWallet, } from "@swapkit/sdk"; const swapKit = SwapKit({ plugins: { ...ThorchainPlugin, }, wallets: { ...keystoreWallet, ...ledgerWallet, }, }); ``` -------------------------------- ### Basic Ethereum setup with SDK and standalone toolbox Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/ethereum.mdx Two ways to set up Ethereum: using the full SDK with createSwapKit and getWallet, or using the standalone EVM toolbox with either a mnemonic phrase or a custom signer and provider. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const ethWallet = await swapKit.getWallet(Chain.Ethereum); ``` ```typescript // @noErrorValidation import { getEthereumToolbox } from '@swapkit/toolboxes/evm'; const ethToolbox = await getEthereumToolbox({ phrase: "your twelve word mnemonic phrase here", derivationPath: [44, 60, 0, 0, 0] }); const ethToolbox = await getEthereumToolbox({ signer: customEthereumSigner, provider: customProvider }); ``` -------------------------------- ### Get Price with SwapKitApi.getPrice Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/api-reference.mdx Import SwapKitApi from @swapkit/helpers/api and fetch a price quote for ETH.ETH in USD. The @noErrorValidation comment suppresses error validation in the example. ```typescript // @noErrorValidation import { SwapKitApi } from "@swapkit/helpers/api"; const price = await SwapKitApi.getPrice({ identifier: "ETH.ETH", currency: "USD", }); ``` -------------------------------- ### Granular Setup with SwapKit and bitgetWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/mobile-desktop/bitget-wallet.mdx Initializes SwapKit with the Bitget wallet extension for frontend applications. Requires an API key from SwapKit. ```ts import { SwapKit, bitgetWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...bitgetWallet }, }); ``` -------------------------------- ### Install SwapKit and node-polyfill-webpack-plugin with yarn Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/nextjs.mdx Use yarn to add the SwapKit SDK and the node-polyfill-webpack-plugin package. ```bash yarn add @swapkit/sdk node-polyfill-webpack-plugin ``` -------------------------------- ### Get Balance and Fee Rates Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/toolbox-usage.mdx Retrieves the balance for a given Bitcoin address and the current fee rates. The example uses a hardcoded address and returns both values. ```ts import { Chain, getUtxoToolbox } from "@swapkit/sdk"; async function getUtxoData() { const btcToolbox = await getUtxoToolbox(Chain.Bitcoin); const address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"; const balance = await btcToolbox.getBalance(address); const feeRates = await btcToolbox.getFeeRates(); return { balance, feeRates }; } ``` -------------------------------- ### Accessing error context with SwapKitError.info Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/core-concepts.mdx Shows how to access the info property of a SwapKitError to get additional context. The example is incomplete in the source, showing only the catch block. ```typescript // @noErrorValidation catch (error) { if (error instanceof SwapKitError) { console.log('Context:', error.info); } } ``` -------------------------------- ### Granular Setup with SwapKit and keplrWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/browser-extensions/keplr.mdx Initializes SwapKit with the Keplr wallet for frontend applications. Requires an API key from SwapKit. ```ts import { SwapKit, keplrWallet, Chain, WalletOption } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...keplrWallet }, }); ``` -------------------------------- ### Generate and Validate Dogecoin Address Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/dogecoin.mdx Get the Dogecoin address from swapKit and validate it. Dogecoin uses a legacy address format starting with 'D' and 34 characters long. ```typescript // @noErrorValidation const dogeAddress = swapKit.getAddress(Chain.Dogecoin); console.log("Dogecoin address:", dogeAddress); const validateDogeAddress = (address: string): boolean => { return address.startsWith("D") && address.length === 34; }; console.log("Valid DOGE address:", validateDogeAddress(dogeAddress)); ``` -------------------------------- ### Modular SwapKit initialization (Recommended) Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/production-best-practices.mdx Use the modular approach to reduce bundle size by importing only the necessary plugins and wallets. This is the recommended way to initialize SwapKit. ```typescript import { SwapKit, ThorchainPlugin, evmWallet } from '@swapkit/sdk'; const swapKit = SwapKit({ plugins: { ...ThorchainPlugin }, wallets: { ...evmWallet } }); ``` -------------------------------- ### Install SwapKit and node-polyfill-webpack-plugin with pnpm Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/nextjs.mdx Use pnpm to add the SwapKit SDK and the node-polyfill-webpack-plugin package. ```bash pnpm add @swapkit/sdk node-polyfill-webpack-plugin ``` -------------------------------- ### Cosmos and THORChain Ledger Setup Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/ledger.mdx Connect a Ledger wallet to Cosmos and THORChain and retrieve addresses. Requires the respective apps installed on the Ledger device. Returns success or error object with addresses. ```ts import { SwapKit, ledgerWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ wallets: { ...ledgerWallet } }); async function setupCosmosEcosystem() { try { await swapKit.connectLedger([Chain.Cosmos]); const cosmosAddress = swapKit.getAddress(Chain.Cosmos); await swapKit.connectLedger([Chain.THORChain]); const thorAddress = swapKit.getAddress(Chain.THORChain); console.log("Cosmos address:", cosmosAddress); console.log("THORChain address:", thorAddress); return { success: true, addresses: { cosmosAddress, thorAddress } }; } catch (error) { return { success: false, error }; } } ``` -------------------------------- ### Granular Setup with phantomWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/browser-extensions/phantom.mdx Recommended for frontend applications. Imports SwapKit, phantomWallet, and Chain, then initializes SwapKit with the phantomWallet spread into the wallets option. ```ts import { SwapKit, phantomWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...phantomWallet }, }); ``` -------------------------------- ### Get token list from provider with SwapKitApi.getTokenList Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/api-reference.mdx Fetches comprehensive token metadata from a specific provider using SwapKitApi.getTokenList. The example uses the 'UNISWAP_V2' provider and shows the returned token object structure. ```typescript // @noErrorValidation const tokens = await SwapKitApi.getTokenList('UNISWAP_V2'); [ { chain: 'ETH', symbol: 'USDC', ticker: 'USDC', identifier: 'ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', decimals: 6, logoURL: 'https: name: 'USD Coin' } ] ``` -------------------------------- ### Get Cosmos Balances and Account Info Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/toolbox-usage.mdx Fetches the balance and account information for a given Cosmos address using the Cosmos toolbox. The example uses a placeholder address and returns both the balances and account info. ```ts import { Chain, getCosmosToolbox } from "@swapkit/sdk"; async function cosmosBalances() { const cosmosToolbox = await getCosmosToolbox(Chain.Cosmos); const address = "cosmos1abcd1234abcd1234abcd1234abcd1234abcd12"; const balances = await cosmosToolbox.getBalance(address); const accountInfo = await cosmosToolbox.getAccount(address); return { balances, accountInfo }; } ``` -------------------------------- ### Import and Initialize UTXO Toolbox Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/toolbox-usage.mdx Imports the getUtxoToolbox function and Chain enum from @swapkit/sdk, then initializes the Bitcoin toolbox. The setupBitcoinToolbox function is async and returns the toolbox instance. ```ts import { Chain, getUtxoToolbox } from "@swapkit/sdk"; async function setupBitcoinToolbox() { const btcToolbox = await getUtxoToolbox(Chain.Bitcoin); return btcToolbox; } ``` -------------------------------- ### Get Polygon toolbox with mnemonic or signer Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/polygon.mdx Use the standalone toolbox to create a Polygon toolbox instance. You can provide a mnemonic phrase with a derivation path, or a custom signer and provider. The example shows both options. ```typescript // @noErrorValidation import { getPolygonToolbox } from '@swapkit/toolboxes/evm'; const polygonToolbox = await getPolygonToolbox({ phrase: "your twelve word mnemonic phrase here", derivationPath: [44, 60, 0, 0, 0] }); const polygonToolbox = await getPolygonToolbox({ signer: customPolygonSigner, provider: customPolygonProvider }); ``` -------------------------------- ### Set up Bitcoin wallet with SwapKit SDK or standalone toolbox Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/bitcoin.mdx Two ways to set up Bitcoin with SwapKit: using the full SDK to get a wallet, or using the standalone Bitcoin toolbox with either a mnemonic phrase or a custom signer. The SDK approach is recommended for most use cases. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const btcWallet = await swapKit.getWallet(Chain.Bitcoin); ``` ```typescript // @noErrorValidation import { getBitcoinToolbox } from '@swapkit/toolboxes/utxo'; const btcToolbox = await getBitcoinToolbox({ phrase: "your twelve word mnemonic phrase here", derivationPath: [84, 0, 0, 0, 0] }); const btcToolbox = await getBitcoinToolbox({ signer: customBitcoinSigner, network: "mainnet" }); ``` -------------------------------- ### Bitcoin Ledger Setup and Transaction Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/ledger.mdx Connect a Ledger wallet to Bitcoin and send a transaction with a custom fee option. Requires the Bitcoin app installed on the Ledger device. Uses FeeOption.Fast and logs available fee rates. ```ts import { SwapKit, ledgerWallet, Chain, FeeOption } from "@swapkit/sdk"; const swapKit = SwapKit({ wallets: { ...ledgerWallet } }); await swapKit.connectLedger([Chain.Bitcoin]); async function bitcoinTransactionWithCustomFee() { const amount = AssetValue.fromChainOrSignature("BTC.BTC", 0.001); const wallet = await swapKit.getWalletWithBalance(Chain.Bitcoin); const feeRates = await wallet.getFeeRates(); console.log("Available fee rates:", feeRates); const txHash = await swapKit.transfer({ assetValue: amount, recipient: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", feeOptionKey: FeeOption.Fast, }); return txHash; } ``` -------------------------------- ### Zcash Operations with Shielded Addresses Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/start/toolbox-usage.mdx Demonstrates Zcash-specific operations: initializing the toolbox with a mnemonic, getting the address, validating transparent and shielded addresses, and transferring funds. The example uses a test mnemonic and a placeholder shielded address. ```ts import { AssetValue, Chain, FeeOption, getUtxoToolbox } from "@swapkit/sdk"; async function zcashOperations() { const zcashToolbox = await getUtxoToolbox(Chain.Zcash, { phrase: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", }); const address = await zcashToolbox.getAddress(); console.log("Zcash address:", address); const isValid = zcashToolbox.validateAddress( "t1XVXWCvpMgBvUaed4XDqWtgQgJSu1Ghz7F" ); console.log("Address valid:", isValid); const shieldedValid = zcashToolbox.validateAddress("zs1z7rejlpsa98s2..."); console.log("Shielded valid:", shieldedValid); const txHash = await zcashToolbox.transfer({ recipient: "t1XVXWCvpMgBvUaed4XDqWtgQgJSu1Ghz7F", assetValue: AssetValue.from({ chain: Chain.Zcash, value: "0.001" }), feeOptionKey: FeeOption.Fast, memo: "Payment memo", }); const keys = await zcashToolbox.createKeysForPath({ phrase: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", derivationPath: "m/44'/133'/0'/0/0", }); return { address, isValid, txHash, keys }; } ``` -------------------------------- ### Create a new Bun + React project Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/bun.mdx Create a new Bun + React project and navigate into its directory. ```bash bun create react my-swapkit-app cd my-swapkit-app ``` -------------------------------- ### Granular Setup with SwapKit Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/ledger.mdx Initializes SwapKit with the granular approach, recommended for frontend applications. Requires an API key and the ledgerWallet wallet. ```ts import { SwapKit, ledgerWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, }, wallets: { ...ledgerWallet }, }); ``` -------------------------------- ### Get Maximum Sendable Zcash Amount Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/zcash-integration.mdx Calculates the maximum amount of Zcash that can be sent from a given address, considering the specified fee option and number of recipients. The example uses the Fast fee option and includes a memo. ```ts import { Chain, FeeOption, getUtxoToolbox } from "@swapkit/sdk"; async function getMaxSendable() { const zcashToolbox = await getUtxoToolbox(Chain.Zcash); const address = "t1XVXWCvpMgBvUaed4XDqWtgQgJSu1Ghz7F"; const maxAmount = await zcashToolbox.estimateMaxSendableAmount({ from: address, feeOptionKey: FeeOption.Fast, recipients: 1, memo: "Maximum transfer", }); console.log("Maximum sendable:", maxAmount.toString()); return maxAmount; } ``` -------------------------------- ### EVM Chains Ledger Setup Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/ledger.mdx Connect a Ledger wallet to multiple EVM chains (Ethereum, Arbitrum, Avalanche, Polygon) and retrieve addresses. Requires the Ethereum app installed on the Ledger device. Returns success or error object. ```ts import { SwapKit, ledgerWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ wallets: { ...ledgerWallet } }); async function setupEVMChains() { const evmChains = [ Chain.Ethereum, Chain.Arbitrum, Chain.Avalanche, Chain.Polygon, ]; try { for (const chain of evmChains) { await swapKit.connectLedger([chain]); const address = swapKit.getAddress(chain); console.log(`${chain} address:`, address); } return { success: true }; } catch (error) { return { success: false, error }; } } ``` -------------------------------- ### Get BSC token balances with toolbox.getBalance Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/bsc.mdx Defines a map of popular BSC token addresses and uses toolbox.getBalance to fetch balances for each token for the current swapKit address on Chain.BinanceSmartChain. The @noErrorValidation comment suppresses type-checking errors in the example. ```typescript // @noErrorValidation const bscTokens = { WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", BUSD: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56", USDT: "0x55d398326f99059fF775485246999027B3197955", USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d", CAKE: "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82", XVS: "0xcF6BB5389c92Bdda8a3747Ddb454cB7a64626C63", VAI: "0x4BD17003473389A42DAF6a0a729f6Fdb328BbBd7", SXP: "0x47BEAd2563dCBf3bF2c9407fEa4dC236fAbA485A", }; const getBSCPortfolio = async () => { const balances = {}; const address = swapKit.getAddress(Chain.BinanceSmartChain); for (const [symbol, tokenAddress] of Object.entries(bscTokens)) { const balance = await toolbox.getBalance(address, tokenAddress); balances[symbol] = balance.toString(); } return balances; }; ``` -------------------------------- ### Validate Dogecoin Address with validateDogecoinAddress Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/dogecoin.mdx Validates Dogecoin addresses using the validateDogecoinAddress function from @swapkit/toolboxes/utxo. The wrapper checks that the address starts with 'D' and has length 34 before delegating to the library. The example tests several addresses and logs whether each is valid or invalid. ```typescript // @noErrorValidation import { validateDogecoinAddress } from "@swapkit/toolboxes/utxo"; const validateDogeAddr = (address: string): boolean => { if (!address.startsWith("D") || address.length !== 34) { return false; } return validateDogecoinAddress(address); }; const testAddresses = [ "DH5yaieqoZN36fDVciNyRueRGvGLR3mr7L", "DFundmtrigzA6E25Swr2pRe4Eb79bGP8G1", "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", "invalid_address", ]; testAddresses.forEach((address) => { const isValid = validateDogeAddr(address); console.log(`${address}: ${isValid ? "Valid" : "Invalid"} DOGE address`); }); ``` -------------------------------- ### Jupiter DEX Integration: Swap and Routes Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/solana.mdx Shows how to get a quote and execute a Jupiter swap, and how to fetch and display all available routes. Uses solToolbox.getJupiterQuote, executeJupiterSwap, and getJupiterRoutes. The example uses hardcoded mint addresses for SOL and USDC, and a slippage of 50 bps. ```typescript // @noErrorValidation const jupiterAdvancedSwap = async () => { const quote = await solToolbox.getJupiterQuote({ inputMint: "So11111111111111111111111111111111111111112", outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 1000000000, slippageBps: 50, }); const swapTx = await solToolbox.executeJupiterSwap({ quote, userPublicKey: swapKit.getAddress(Chain.Solana), priorityFee: 10000, }); console.log("Jupiter swap executed:", swapTx); }; const getAllRoutes = async () => { const routes = await solToolbox.getJupiterRoutes({ inputMint: "So11111111111111111111111111111111111111112", outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", amount: 1000000000, }); routes.forEach((route, index) => { console.log(`Route ${index + 1}:`); console.log(` Output: ${route.outAmount}`); console.log(` Price impact: ${route.priceImpactPct}%`); console.log( ` Market infos:`, route.marketInfos.map((m) => m.label) ); }); }; ``` -------------------------------- ### Set up SwapKit client with API keys Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/integrations/nextjs.mdx Creates a SwapKit client instance and configures API keys from environment variables. Requires NEXT_PUBLIC_SWAPKIT_API_KEY and NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID to be set. ```typescript // @noErrorValidation import { createSwapKit } from "@swapkit/sdk"; import { SKConfig } from "@swapkit/sdk"; if (process.env.NEXT_PUBLIC_SWAPKIT_API_KEY) { SKConfig.setApiKey("swapKit", process.env.NEXT_PUBLIC_SWAPKIT_API_KEY); } if (process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID) { SKConfig.setApiKey( "walletConnectProjectId", process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID ); } export const swapKitClient = createSwapKit(); ``` -------------------------------- ### Cross-Chain Swap from ATOM using swapKit Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/cosmos.mdx Shows how to get quotes and execute a THORChain cross-chain swap from Cosmos Hub ATOM to BTC, USDC on Ethereum, and RUNE. Uses swapKit.getQuote and swapKit.swap with FeeOption.Fast. The example includes logging the quote details and performing the swap. ```typescript // @noErrorValidation const atomToBtcQuote = await swapKit.getQuote({ sellAsset: "GAIA.ATOM", sellAmount: "100", buyAsset: "BTC.BTC", senderAddress: swapKit.getAddress(Chain.Cosmos), recipientAddress: swapKit.getAddress(Chain.Bitcoin), }); console.log("ATOM -> BTC quote:", { expectedOutput: atomToBtcQuote.expectedOutput, fees: atomToBtcQuote.fees, timeEstimate: atomToBtcQuote.timeEstimate, }); const swapTx = await swapKit.swap({ route: atomToBtcQuote.routes[0], feeOptionKey: FeeOption.Fast, }); const atomToUsdcQuote = await swapKit.getQuote({ sellAsset: "GAIA.ATOM", sellAmount: "50", buyAsset: "ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", senderAddress: swapKit.getAddress(Chain.Cosmos), recipientAddress: swapKit.getAddress(Chain.Ethereum), }); const atomToRuneQuote = await swapKit.getQuote({ sellAsset: "GAIA.ATOM", sellAmount: "25", buyAsset: "THOR.RUNE", senderAddress: swapKit.getAddress(Chain.Cosmos), recipientAddress: swapKit.getAddress(Chain.THORChain), }); ``` -------------------------------- ### Configure BCH testnet and get testnet address Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/bitcoin-cash.mdx Set up a Bitcoin Cash testnet environment by setting a testnet RPC URL, disabling mainnet with SKConfig.setEnv('isMainnet', false), and creating a testnet toolbox with a custom derivation path. The example then retrieves and logs the testnet address. ```typescript // @noErrorValidation SKConfig.setRpcUrl(Chain.BitcoinCash, "https: SKConfig.setEnv('isMainnet', false); const testnetToolbox = await getBitcoinCashToolbox({ phrase: "your mnemonic", network: "testnet", derivationPath: [44, 1, 0, 0, 0] }); const testnetAddress = testnetToolbox.getAddress(); console.log("BCH Testnet address:", testnetAddress); ``` -------------------------------- ### Basic Wallet Adapter Example with createWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/create-wallet.mdx Creates a custom wallet adapter using `createWallet` from `@swapkit/sdk`. The adapter supports Ethereum, BinanceSmartChain, Avalanche, and Polygon chains, and connects by requesting accounts from `window.ethereum` and adding each chain via `addChain` with the EVM toolbox. Throws an error if the provider is not found. ```ts import { Chain, DerivationPath, NetworkDerivationPath, createWallet, type ChainWallet, type EVMChain, getEvmToolbox, } from "@swapkit/sdk"; export const myCustomWallet = createWallet({ name: "connectMyCustomWallet", walletType: "custom", supportedChains: [ Chain.Ethereum, Chain.BinanceSmartChain, Chain.Avalanche, Chain.Polygon, ], connect: ({ addChain, supportedChains, walletType }) => async function connectMyCustomWallet(chains: typeof supportedChains) { const filteredChains = chains.filter((chain) => supportedChains.includes(chain) ); if (filteredChains.length === 0) { return false; } for (const chain of filteredChains) { const provider = window.ethereum; if (!provider) { throw new Error("Provider not found"); } const accounts = await provider.request({ method: "eth_requestAccounts", }); const address = accounts[0]; const toolbox = await getEvmToolbox(chain, { provider, }); addChain({ ...toolbox, chain, walletType, address, }); } return true; }, }); ``` -------------------------------- ### Manage Token Lists with SwapKitApi.getTokenList() Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/advanced-features.mdx Loads token lists from a provider with caching, adds custom tokens to the registry, and retrieves tokens by identifier. The TokenRegistry class uses a Map for storage and a cache with a TTL of 3600000 ms. The example shows loading provider tokens, adding a custom token, and getting a token. ```typescript // @noErrorValidation import { AssetValue, ProviderName } from '@swapkit/sdk'; import { SwapKitApi } from '@swapkit/helpers/api'; async function loadTokenList(provider: ProviderName) { const tokenList = await SwapKitApi.getTokenList(provider); return tokenList.tokens; } class TokenRegistry { private tokens: Map = new Map(); private cache: Map = new Map(); private cacheTTL = 3600000; async loadProviderTokens(provider: ProviderName) { const cacheKey = `provider_${provider}`; const cached = this.cache.get(cacheKey); if (cached && Date.now() - cached.timestamp < this.cacheTTL) { return cached.data; } const tokenList = await SwapKitApi.getTokenList(provider); this.cache.set(cacheKey, { data: tokenList, timestamp: Date.now() }); tokenList.tokens.forEach(token => { this.tokens.set(token.identifier, token); }); return tokenList; } addCustomToken(token: { chain: string; identifier: string; symbol: string; decimals: number; name?: string; logoURI?: string; address?: string; }) { this.tokens.set(token.identifier, token); AssetValue.setStaticAssets(new Map([[token.identifier, { identifier: token.identifier, chain: token.chain, decimal: token.decimals }]])); } getToken(identifier: string) { return this.tokens.get(identifier); } } const registry = new TokenRegistry(); await registry.loadProviderTokens(ProviderName.UNISWAP); registry.addCustomToken({ chain: 'ETH', identifier: 'ETH.CUSTOM-0x1234567890123456789012345678901234567890', symbol: 'CUSTOM', decimals: 18, name: 'Custom Token', logoURI: 'https: }); ``` -------------------------------- ### Set Up Radix Wallet with SDK or Toolbox Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/chains/radix.mdx Two ways to set up Radix: using the full SDK with createSwapKit and getWallet, or using the standalone Radix toolbox with getRadixToolbox. The toolbox example shows two configurations: one with a mnemonic phrase and derivation path, and another with a private key and network ID. ```typescript // @noErrorValidation import { createSwapKit, Chain } from '@swapkit/sdk'; const swapKit = createSwapKit(); const radixWallet = await swapKit.getWallet(Chain.Radix); ``` ```typescript // @noErrorValidation import { getRadixToolbox } from '@swapkit/toolboxes/radix'; const radixToolbox = await getRadixToolbox({ phrase: "your twelve word mnemonic phrase here", derivationPath: [44, 1022, 0, 0, 0] }); const radixToolbox = await getRadixToolbox({ privateKey: customRadixPrivateKey, networkId: 1 }); ``` -------------------------------- ### Granular Setup with SwapKit and trezorWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/hardware/trezor.mdx Initializes SwapKit with the trezorWallet integration using the granular approach, recommended for frontend applications. Requires an API key and Trezor integration config with appName, appUrl, and email. ```typescript import { SwapKit, trezorWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", }, integrations: { trezor: { appName: "Your App Name", appUrl: "https: email: "support@yourapp.com", }, }, }, wallets: { ...trezorWallet }, }); ``` -------------------------------- ### Granular Setup with SwapKit and walletconnectWallet Source: https://github.com/swapkit/swapkit/blob/develop/docs/src/content/docs/guides/wallets/mobile-desktop/walletconnect.mdx Initializes SwapKit with the granular approach, recommended for frontend applications. Requires API keys for SwapKit and WalletConnect project ID. ```ts import { SwapKit, walletconnectWallet, Chain } from "@swapkit/sdk"; const swapKit = SwapKit({ config: { apiKeys: { swapKit: "your-api-key", walletConnectProjectId: "your-walletconnect-project-id", }, }, wallets: { ...walletconnectWallet }, }); ```