Overview
TheuseQuotes hook manages the complete lifecycle of token swaps, from fetching quotes to executing transactions and monitoring their status. It handles wallet integration, quote expiration, and automatic status polling.
Import
Signature
Return Values
Quote | null
The current quote object containing swap details, pricing, and chain operations.
null when no quote is active.QuoteStatus | null
Real-time transaction status after quote execution. Updates automatically via polling. Includes transaction hashes and explorer URLs.
boolean
Indicates if a quote fetch or transaction execution is in progress.
string | null
Error message if quote fetching or execution fails.
null when no errors.boolean
Indicates if the hook is actively polling for transaction status updates.
string | null
The user’s predicted account address (smart contract wallet). Required for balance checks and quote requests.
() => Promise<string | null>
Async function to fetch the user’s predicted account address. Called automatically when needed.
(request: SimpleQuoteRequest) => Promise<Quote | void>
Fetches a new swap quote based on the provided parameters.Parameters:
SimpleQuoteRequest
required
Quote request parameters
() => Promise<void>
Executes the current quote. Signs the quote using the embedded wallet and submits it for processing. Automatically starts polling for transaction status.Requirements:
- User must be authenticated
- Quote must exist and not be expired
- Embedded wallet must be available
() => void
Clears the current quote, status, errors, and stops any active polling. Use when canceling a quote or resetting the swap form.
Usage Examples
Basic Swap Flow
With Transaction Status Tracking
Debounced Quote Fetching
Quote Expiration Handling
Types
Quote
QuoteStatus
Notes
- The hook automatically polls for transaction status every 1 second after execution
- Polling stops when the transaction reaches
COMPLETEDorFAILEDstatus - Quote validation checks expiration time before execution
- Requires Privy authentication and embedded wallet
- Uses the
PredictedAddressContextfor account management
Related Hooks
- useEmbeddedWallet - Get the user’s embedded wallet
- useBalances - Fetch user token balances
- useAssets - Get available assets for swapping
See Also
- Quote API - Backend API for quotes
- Swap Tutorial - Complete swap implementation guide