Hooks
useGetSwapQuote
Hook for fetching quotes for a swap
Import
Usage
Return Type: UseQueryResult<LifiSwapQuote>
The hook returns all properties from React Query’s UseQueryResult
with swap quote data. Here’s the detailed structure of the swapQuote.
Properties
data
SwapQuote | undefined
The swap quote object containing:
currencyAddress
: Address of the currency to be swappedcurrencyBalance
: Balance of the currency in the user’s walletprice
: The current price for the swapmaxPrice
: Maximum price allowed for the swap (includes slippage)to
: The target contract address that handles the swaptransactionData
: Encoded transaction data for executing the swaptransactionValue
: The value to be sent with the transaction (for native tokens)approveData
: Encoded approval transaction data (if includeApprove is true and needed)amount
: The amount of currency to be receivedamountMin
: The minimum amount to be received after slippage
isLoading
boolean
Loading state for the data fetch.
isError
boolean
Error state indicating if the query failed.
error
Error | null
Any error that occurred during data fetching.
Parameters
The hook accepts two parameters:
args: GetLifiSwapQuoteArgs
Parameter | Type | Description |
---|---|---|
params.chainId | number | The chain ID where the swap will occur |
params.walletAddress | string | The address of the user’s wallet |
params.fromTokenAddress | string | The address of the token to sell |
params.toTokenAddress | string | The address of the token to buy |
params.fromTokenAmount | string | (Optional) The amount of token to sell (in wei) |
params.toTokenAmount | string | (Optional) The amount of token to buy (in wei) |
params.includeApprove | boolean | Whether to include approval transaction data |
params.slippageBps | number | Maximum allowed slippage in basis points (100 = 1%) |
Note: You must provide either fromTokenAmount
or toTokenAmount
, but not both.
options: HooksOptions
Parameter | Type | Description |
---|---|---|
disabled | boolean | (Optional) Disable the query from automatically running |
retry | boolean | (Optional) Whether to retry failed queries (defaults to true) |