Skip to main content
This guide shows a browser swap flow from start to finish, then two variations: building the transaction yourself, and streaming ready-to-sign swaps. For a server-side script, see the Raptor quickstart.
HTTP: https://raptor.solanatracker.io · WebSocket: wss://raptor.solanatracker.io. No API key needed.

Swap from a browser wallet

The example uses @solana/web3.js and any wallet that exposes signTransaction (Phantom, Solflare, Wallet Adapter).

Show the price before signing

If the user should confirm the price first, show the quote fields, then build the transaction once they accept. Fetch a new quote if they wait more than a few seconds.

Common options

On /quote: On /swap: Raptor creates any token accounts the user is missing and wraps and unwraps SOL inside the transaction. The user pays the rent for new token accounts (about 0.002 SOL each).

Quote and build in one call

When the user doesn’t need to review the price, POST /quote-and-swap takes the quote parameters and the wallet together and returns both:

Build your own transaction

Use POST /swap-instructions to add your own instructions, such as a memo or a transfer, around the swap. It takes the same body as /swap.
Sign and send it as in the browser example. Two things to know:
  • If the response includes quoteResponse, the route was rebuilt. Show the user those amounts.
  • /swap-instructions returns an ordinary swap that you can also call from your own program through CPI. If you ask for jitRouting: true, the response has topLevelOnly: true, and the swap must be the last top-level instruction. See JIT routing.

Stream ready-to-sign swaps

/stream/swap sends a new quote and a freshly built transaction whenever the best route changes. When the user clicks Swap, sign the latest transaction and send it. There’s no separate build step.
For prices only, use /stream instead. It takes the same subscribe message without userPublicKey, and its updates have type: "quote" with the quote in data.

Raptor overview

Parameters, JIT routing, errors and supported DEXes.

Transactions

Status values and reading swap results.