Hook for fetching available routes for a swap
This hook replaces the useGetSwapPrices
hook which was removed in v5.2.3.
UseQueryResult<LifiSwapRoute[]>
The hook returns all properties from React Query’s UseQueryResult
with swap routes data. Here’s the detailed structure of the LifiSwapRoute
object:
LifiSwapRoute[] | undefined
Array of swap route objects containing:
fromChainId
: The chain ID of the token to selltoChainId
: The chain ID of the token to buyfromTokens
: Array of tokens that can be used to pay for the swaptoTokens
: Array of tokens that can be received from the swapboolean
Loading state for the data fetch.
boolean
Error state indicating if the query failed.
Error | null
Any error that occurred during data fetching.
The hook accepts two parameters:
UseGetSwapRoutesArgs
Parameter | Type | Description |
---|---|---|
walletAddress | string | The address of the user’s wallet |
toTokenAddress | string | The address of the token to buy |
chainId | number | The chain ID where the swap will occur |
toTokenAmount | string | The amount of token to buy (in wei) |
HooksOptions
Parameter | Type | Description |
---|---|---|
disabled | boolean | (Optional) Disable the query from automatically running |
retry | boolean | (Optional) Whether to retry failed queries (defaults to true) |
Hook for fetching available routes for a swap
This hook replaces the useGetSwapPrices
hook which was removed in v5.2.3.
UseQueryResult<LifiSwapRoute[]>
The hook returns all properties from React Query’s UseQueryResult
with swap routes data. Here’s the detailed structure of the LifiSwapRoute
object:
LifiSwapRoute[] | undefined
Array of swap route objects containing:
fromChainId
: The chain ID of the token to selltoChainId
: The chain ID of the token to buyfromTokens
: Array of tokens that can be used to pay for the swaptoTokens
: Array of tokens that can be received from the swapboolean
Loading state for the data fetch.
boolean
Error state indicating if the query failed.
Error | null
Any error that occurred during data fetching.
The hook accepts two parameters:
UseGetSwapRoutesArgs
Parameter | Type | Description |
---|---|---|
walletAddress | string | The address of the user’s wallet |
toTokenAddress | string | The address of the token to buy |
chainId | number | The chain ID where the swap will occur |
toTokenAmount | string | The amount of token to buy (in wei) |
HooksOptions
Parameter | Type | Description |
---|---|---|
disabled | boolean | (Optional) Disable the query from automatically running |
retry | boolean | (Optional) Whether to retry failed queries (defaults to true) |