Alchemy Logo

usePrepareSwap

function usePrepareSwap(params): UsePrepareSwapResult;

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.

import { usePrepareSwap } from "@account-kit/react";
 
const { prepareSwapAsync, isPreparingSwap, error } = usePrepareSwap();
 
// Request a swap quote
const quote = await prepareSwapAsync({
  fromToken: "0x...",
  toToken: "0x...",
  minimumToAmount: "0x...",
});

ParameterTypeDescription

params

UsePrepareSwapParams

Configuration parameters for the hook

UsePrepareSwapResult

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

  • 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 useSignAndSendPreparedCalls to complete the swap.
Was this page helpful?