Swap
Swap one asset for another across on-chain venues (Aquarius AMM, Soroswap, SDEX). Pollar quotes every route, ranks them best-first and renders the whole quote-and-swap flow inside a modal.
Venues are configured in your dashboard
The swap modal only offers the venues you enable under Treasury → Swap in the Pollar dashboard. The SDK reads that selection at runtime via getSwapConfig() (the SDK_SWAP_CONFIG response) — no code change needed. An empty list hides the swap UI entirely.
GET /swap/config →
{
"content": { "venues": ["aquarius", "sdex"] },
"code": "SDK_SWAP_CONFIG",
"success": true
}Drop-in button that opens a prebuilt modal — the whole quote → swap flow (trustline included) is rendered for you.
openSwapModal() takes no arguments — assets, amount and venue are picked inside the modal.
Hook & values used
All of these come from the usePollar() hook — the react layer built on top of getClient().
usePollar()hookparams: No arguments. Call it at the top level of a component — it reads React context, so it must run during render.
returns: PollarContextValue — the whole SDK surface: reactive state values, modal openers, and getClient() to drop down to core.
getSwapConfig()asyncparams: No arguments — resolves the venues this app exposes, from your dashboard selection (Treasury → Swap).
returns: Promise<SwapVenue[]> — enabled venues; empty means swap is disabled for this app, so hide the swap UI.
openSwapModal()syncparams: No arguments — assets, amount and venue are picked inside the modal.
returns: void — opens the prebuilt modal; there is nothing to await.
import { usePollar } from '@pollar/react'; export function SwapButton() { const { openSwapModal, isAuthenticated } = usePollar(); // openSwapModal renders the whole quote → swap flow on top of // client.getSwapQuote / client.swap (trustline handled for you). return ( <button onClick={openSwapModal} disabled={!isAuthenticated} > Swap tokens </button> ); }