usePrepareSwap

1function 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.

Example

import { 
function usePrepareSwap(params: UsePrepareSwapParams): UsePrepareSwapResult

Hook 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: boolean
isPreparingSwap
,
const error: Error | null
error
} =
function usePrepareSwap(params: UsePrepareSwapParams): UsePrepareSwapResult

Hook 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: RequestQuoteV0Result
quote
= 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

ParameterTypeDescription

params

UsePrepareSwapParams

Configuration parameters for the hook

Returns

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

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 useSignAndSendPreparedCalls to complete the swap.