usePrepareSwap
Defined in: account-kit/react/src/hooks/usePrepareSwap.ts:85
Hook for requesting swap quotes from a smart account.
This hook provides functionality to request swap quotes for token swaps.
Example
import { function usePrepareSwap(params: UsePrepareSwapParams): UsePrepareSwapResultHook for requesting swap quotes from a smart account.
This hook provides functionality to request swap quotes for token swaps.
usePrepareSwap } from "@account-kit/react";
const { const prepareSwapAsync: UseMutateAsyncFunction<RequestQuoteV0Result, Error, MutationParams, unknown>prepareSwapAsync, const isPreparingSwap: booleanisPreparingSwap, const error: Error | nullerror } = function usePrepareSwap(params: UsePrepareSwapParams): UsePrepareSwapResultHook for requesting swap quotes from a smart account.
This hook provides functionality to request swap quotes for token swaps.
usePrepareSwap();
// Request a swap quote
const const quote: RequestQuoteV0Resultquote = await const prepareSwapAsync: (variables: MutationParams, options?: MutateOptions<RequestQuoteV0Result, Error, MutationParams, unknown> | undefined) => Promise<RequestQuoteV0Result>prepareSwapAsync({
  fromToken: "0x..."fromToken: "0x...",
  toToken: "0x..."toToken: "0x...",
  minimumToAmount: "0x..."minimumToAmount: "0x...",
});Parameters
Returns
An object containing:
- prepareSwap: Function to request quote and prepare the swap synchronously
- prepareSwapAsync: Async function to request quote and prepare the swap (returns Promise)
- quote: The result of the last successful quote request
- isPreparingSwap: Boolean indicating if a quote is currently being requested
- error: Error from the last failed quote request, if any
Description
- This hook only works with smart accounts and does not support EOA wallets
- The hook handles the quote request step of the swap flow
- The returned quote can be used with useSignAndSendPreparedCallsto complete the swap.