Overview
Swap mode provides a flexible interface for cross-chain token exchanges. Users control both input and output selections, with the widget handling optimal routing across bridges and DEXs. Trade Types: Supports bothEXACT_INPUT and EXACT_OUTPUT trade types.
Configuration
Required Props
| Prop | Type | Description |
|---|---|---|
mode | "swap" | Sets the widget to swap mode |
Optional Props
| Prop | Type | Description |
|---|---|---|
fromChainId | number | Pre-select source chain |
fromToken | string | Pre-select source token |
toChainId | number | Pre-select destination chain |
toToken | string | Pre-select destination token |
slippageTolerance | string | number | Slippage tolerance (default: 0.5%) |
swapProvider | RouteProvider | Swap provider: "AUTO", "RELAY", "SUSHI", "ZEROX", "CCTP" |
bridgeProvider | RouteProvider | Bridge provider: "AUTO", "RELAY", "CCTP" |
Widget Implementation
Basic Swap Widget
Minimal configuration - users select everything:Pre-configured Swap
Pre-select chains and tokens:Custom Route Provider
Specify routing preference:Headless Implementation with useQuote
For custom UI implementations, use theuseQuote hook directly:
Basic useQuote Implementation
Trade Types
EXACT_INPUT
User specifies exact input amount; output amount varies:EXACT_OUTPUT
User specifies exact output amount; input amount varies:Quote Types
Quote Refresh Strategy
Quotes can become stale. Implement refresh logic:Event Handling
Widget Events
useQuote Transaction Status
Error Handling
Use Cases
- Cross-chain Token Exchange: Swap any token to any other token across chains
- Portfolio Rebalancing: Shift holdings between chains and tokens
- Yield Optimization: Move assets to chains with better yields
- Gas Token Acquisition: Get native tokens for new chains
- Arbitrage: Take advantage of price differences across chains
Technical Notes
- Quotes automatically factor in gas costs and fees
- Multiple liquidity sources are queried for optimal routing
- Supports both same-chain and cross-chain swaps
- Native token wrapping/unwrapping is handled automatically
- Slippage protection is built-in
See Also
- Use Case Examples - Implementation patterns
- Quote Providers - Provider comparison and selection
- Hooks Reference - useQuote hook details
- Configuration - Additional configuration options