Skip to main content
function executeSwap(options: ExecuteSwapOptions): Promise<ExecuteSwapResult>;
Executes a token swap on behalf of the signed-in user. The backend atomically quotes, signs Permit2 (if needed), simulates, and submits the transaction. Returns immediately with a transaction hash (EOA) or user operation hash (smart account).

Parameters

ParameterTypeDescription
optionsExecuteSwapOptionsThe swap execution parameters.

Returns

Promise<ExecuteSwapResult> A discriminated union result with the transaction/operation hash and swap details.

Throws

An InputValidationError if parameters are invalid.

Throws

A SwapError for known failures (insufficient liquidity/balance/allowance, simulation failure).

Throws

An APIError for auth, network, or server errors.

Example

const result = await executeSwap({
  network: "base",
  fromToken: "0x4200000000000000000000000000000000000006",
  toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  fromAmount: "100000000000000000",
  slippageBps: 100,
});

if (result.type === "evm-eoa") {
  console.log("Transaction hash:", result.transactionHash);
} else {
  console.log("User operation hash:", result.userOpHash);
}