useQuote
Fetch quotes from all configured aggregators, simulate them, and select a winner using a strategy.
Example
import { useQuote } from "@spandex/react";
function App() {
const { data, isLoading, error } = useQuote({
swap: {
inputToken: "0x4200000000000000000000000000000000000006", // WETH
outputToken: "0xd9AAEC86B65D86f6A7B5B1b0c42FFA531710b6CA", // USDbC
mode: "exactIn",
inputAmount: 1_000_000_000_000_000_000n, // 1 WETH
slippageBps: 50, // Tolerance
},
strategy: "bestPrice",
});
}Returns
{
data: SuccessfulSimulatedQuote | null | undefined;
isLoading: boolean;
error: Error | null;
// ...other React Query return values
}Params
swap
The swap parameters, with optional chainId and swapperAccount (inferred from the current
connection if omitted) and optional recipientAccount (defaults to swapperAccount).
swap params
inputToken: string- The input token address.outputToken: string- The output token address.mode: "exactIn" | "targetOut"- The swap mode.inputAmount?: bigint- The input amount (required if mode is "exactIn").outputAmount?: bigint- The desired output amount (required if mode is "targetOut").slippageBps: number- The slippage tolerance in basis points.recipientAccount?: string- Optional output recipient address.
strategy
Defines how to choose the winning quote. Built-in strategies are "fastest", "bestPrice",
"estimatedGas", and "priority". You can also supply a serializable strategy plan or a custom
selection function.
For strategy tradeoffs and collector/ranker composition examples, see Strategies.
When using function strategies, or strategy plans that contain custom collect or rank
functions, memoize them so the query key stays stable across renders.
query
Optional React Query overrides (for example enabled, staleTime, or select). queryKey and queryFn are managed by spanDEX and cannot be provided.