executeQuote
Execute a simulated quote onchain using a wallet client. Handles approval requirements and supports EIP-5792 batch calls when available.
Example
import { executeQuote, getQuote } from "@spandex/core";
import { config, publicClient, walletClient } from "./config.js";
const swap = {
chainId: 8453,
inputToken: "0x4200000000000000000000000000000000000006", // WETH
outputToken: "0xd9AAEC86B65D86f6A7B5B1b0c42FFA531710b6CA", // USDbC
mode: "exactIn",
inputAmount: 1_000_000_000_000_000_000n, // 1 WETH
slippageBps: 50, // Tolerance
swapperAccount: "0x1234567890abcdef1234567890abcdef12345678",
};
const quote = await getQuote({
config,
swap,
strategy: "bestPrice",
});
if (!quote) {
throw new Error("No providers returned a successful quote");
}
const result = await executeQuote({
config,
swap,
quote,
walletClient,
publicClient,
});
console.log(result.transactionHash);Params
swap
SwapParams
Swap parameters used to build the approval + swap transactions.
quote
SimulatedQuote
The simulated quote to be executed. This should be obtained via getQuotes or getQuote. If the quote is not successful, executeQuote throws an ExecutionError.
config
Config
Aggregator configuration object created via createConfig. Used to resolve clients and options.
walletClient
WalletClient
A Viem wallet client configured with the swapper's account and chain. This client is used to sign and send the transaction.
publicClient
PublicClient | undefined
Optional public client for onchain reads (allowance checks, gas estimation, and receipt polling). If omitted, the configured client for the swap chain is used.
Returns
Promise<ExecutedQuoteReturnType>
A promise for an execution result containing the transaction hash.