Swap APIs & SDKs

Build calldata for a PancakeSwap aggregator candidate

Turn a PancakeSwap agg candidate into calldata while preserving its route and revalidating recipient, slippage and funding.

For an agg candidate, use the documented calldata builder and then construct a wallet transaction from its returned destination, call data and native value. The route object itself is not a transaction.

PancakeSwap documents POST /v1/calldata as accepting the aggregator candidate. Its response uses calldata rather than the data field many wallet libraries expect. Convert the field name and numeric representation without changing the payload.

Preserve the route artifact

Keep the agg object associated with its original chain and request. Do not edit split legs to improve the displayed output or remove a pool from the JSON. A route is a coherent instruction set, and changing one part can invalidate the encoding or execution.

Recipient and slippage have documented builder semantics. If the application permits either to change, treat that as a new review context and invalidate any previously built transaction. A backend accepting these fields should validate them against the user's current request rather than trusting a stale browser object.

Before sending

Check the returned destination using the expected deployment rules. Resolve the token allowance for the selected execution path, preserve value, simulate the actual sender and estimate gas. The API builder does not replace those wallet-side responsibilities.

The official TypeScript example illustrates the mapping into sendTransaction. Treat it as an integration reference; this publication does not claim to have executed it.

Test missing optional inline calldata, expired candidates, mismatched recipient and native input. A successful quote followed by a failed build should leave the form with an estimate and an unavailable execution state, not a fabricated transaction assembled from partial fields.

Sources & verification (2)

Source-check date is recorded in the article details. URLs are provided for manual verification. Use Copy to keep this page open.

  1. Endpoints

    Quote, calldata, submit and status contracts

    https://developer.pancakeswap.finance/contracts/unified-swap-api/endpoints
  2. TypeScript examples

    Different approval and execution paths for agg and pcsx candidates

    https://developer.pancakeswap.finance/contracts/unified-swap-api/typescript

Continue reading

Swap API integration: quote, approve, simulate, submit