UX.SOL

Component

Token Swap Card

Provides a token swap interface with token inputs, slippage options, and confirmation states.

Preview

SOL
USDC

Swap tokens

1 SOL = 142.3000 USDC
You pay
You receive
0.00
Slippage: 0.5%
Fee: ~0.000005 SOL

Installation

terminal
$npx shadcn@latest add https://uxdotsol.xyz/r/token-swap.json

Usage

token-swap.tsx
import { TokenSwap } from "@/components/token-swap";
 
export default function App() {
return (
<div className="flex justify-center p-8">
<TokenSwap />
</div>
);
}

Props / Arguments

NameTypeDefaultDescription
tokensToken[]DEFAULT_TOKENSList of tokens available for selection in the dropdowns.
defaultFromTokentokens[0]Pre-selected pay-side token.
defaultToTokentokens[1]Pre-selected receive-side token.
slippageOptionsnumber[][0.1, 0.5, 1.0]Available slippage tolerance options shown as pills (in percent).
rateLabelstringundefinedStatic exchange rate label used when USD prices are unavailable.
networkFeestring'~0.000005 SOL'Network fee string shown in the card footer.
onSwap(from: Token, to: Token, amount: string) => voidundefinedCallback fired after the swap animation completes. Use this to trigger the real transaction.
classNamestring''Optional Tailwind / CSS class forwarded to the card root element.