Skip to main content

Overview

The useQuotes 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 COMPLETED or FAILED status
  • Quote validation checks expiration time before execution
  • Requires Privy authentication and embedded wallet
  • Uses the PredictedAddressContext for account management

See Also