Swap

Token exchange interface with automatic quote calculation, slippage protection, and balance checking.

Overview

The Swap component provides a complete token swapping interface. It automatically calculates exchange rates, checks token balances, handles approvals, and executes swaps with slippage protection.

Props

Props

NameTypeDefaultDescription
onSuccess(txHash: string) => void-Callback fired when swap succeeds
onError(error: string) => void-Callback fired when swap fails
supportedTokensTokenSymbol[]['USDT', 'USDC', 'WETH', 'DAI']List of supported tokens for swapping
defaultFromTokenTokenSymbol'USDT'Default token to swap from
defaultToTokenTokenSymbol'USDC'Default token to swap to

Basic Usage

SwapExample.tsx
import { Swap } from 'hyperkit';

function App() {
  return (
    <Swap />
  );
}

Token Selection

Configure supported tokens and default selections:

CustomTokens.tsx
import { Swap } from 'hyperkit';

function App() {
  return (
    <Swap
      supportedTokens={['USDT', 'USDC', 'WETH']}
      defaultFromToken="USDT"
      defaultToToken="USDC"
    />
  );
}

Slippage Protection

The Swap component includes built-in slippage protection. Users can adjust slippage tolerance, and the component will ensure the minimum output amount is met before executing the swap.