Skip to main content
Quotes are price snapshots at a specific block. Pool reserves, tick state, and competing trades can move the market between the moment you quote and the moment your transaction lands. The aggregator handles this with a short server-side cache TTL and explicit expiry semantics.

The contract

TTL is ~10 seconds

Each /quote response includes expiresAt (Unix milliseconds). The default TTL is 10 seconds. After that, the cache entry is gone.

/submit returns 404 on expired quotes

Once expiresAt has passed, POST /submit with that quoteId returns { "error": "quote not found or expired" }. Re-quote and retry.
1

Fetch a fresh quote when the swap modal opens

On modal open, call /quote and store the result. Display the price.
2

Re-quote on a 5 to 8 second interval

While the modal is open, re-fetch the quote periodically. Compare expectedAmountOut against the previous value to decide whether to flash an “updated” indicator.
3

Stop polling on user action

When the user clicks “Swap” (or your equivalent), pause polling so the price doesn’t change between their decision and the wallet prompt.
4

Submit using the latest quoteId

Always submit using the quoteId from the most recent successful /quote. Don’t reuse an older one.
5

Handle 404 gracefully

If /submit returns 404, automatically re-fetch /quote and retry once. Only surface a user-facing error if the second attempt also fails.

Reference implementation

Then in the swap submit handler:

Why not use /execute for this?

/execute always returns a fresh quote, so it sidesteps the 404 problem. But:
  • You lose the ability to display the quoted price before the user signs.
  • Every /execute call burns rate-limit budget and re-runs the routing engine, so it’s more expensive than alternating /quote and /submit.
Use /execute for one-click flows where preview doesn’t matter. Use the two-step pattern with the freshness loop above for any UI that shows a price.

Slippage as a freshness backstop

Even with aggressive re-quoting, your submitted transaction may land 1-2 blocks after /quote ran. Use slippageBps as the safety margin: The user’s minAmountOut is set on the router, so the swap reverts cleanly if real output falls below the slippage threshold — your transaction never lands in a worse-than-expected state.
Cache the user’s preferred slippage per pair-type. Forcing the user to set slippage manually on every swap is a common UX pitfall.