- Raydium is a leading Solana AMM. Its hosted Trade API quotes and builds a swap for you, routing across Raydium’s pool types (AMM v4, CPMM, CLMM) so you don’t manage pool data yourself.
- The flow: fetch a priority fee, get a quote, build the transaction, then sign it with
@solana/web3.jsand send it through your own Solana node. - This guide swaps SOL → USDC in TypeScript using a Chainstack Solana node for the broadcast.
Main article
The Solana blockchain is at the forefront of DeFi, known for its speed and cost-efficiency. Central to this ecosystem is Raydium, an automated market maker (AMM) that provides deep liquidity across several pool types — legacy AMM v4, constant-product CPMM, and concentrated-liquidity CLMM. You don’t need to know which pool a pair trades in. Raydium’s Trade API computes the best route across all of them, returns a quote, and builds a ready-to-sign transaction. This guide walks through a SOL → USDC swap in TypeScript, signing and broadcasting through a Chainstack Solana node.Prerequisites
Deploy a Chainstack Solana node
Deploy a Solana RPC endpoint on Chainstack:Sign up with Chainstack
Deploy a node
View node access and credentials
Local setup
- Node.js 18 or above (for the global
fetchused below) - A Solana wallet with some SOL to cover the swap and fees
Implementation
The Trade API exposes two hosts:https://api-v3.raydium.io for general data (including the priority-fee endpoint) and https://transaction-v1.raydium.io for the swap compute and build endpoints. The flow is fetch fee → quote → build → sign → send.
raydium_swap.ts
tsx:
How it works
- Priority fee.
GET /main/auto-feereturns suggested compute-unit prices in three tiers —vh(very high),h(high), andm(medium). Pass the chosen tier ascomputeUnitPriceMicroLamportsin the build request; Raydium adds the compute-budget instructions for you. - Quote.
GET /compute/swap-base-intakes the input/output mints, the inputamount(in the input token’s smallest unit), andslippageBps.swap-base-inmeans you fix the input amount; useswap-base-outto fix the output amount instead. Raydium returns the best route and the expectedoutputAmount. - Build.
POST /transaction/swap-base-inreturns one or more base64 transactions. SetwrapSol: truewhen the input is native SOL (it wraps to WSOL) andunwrapSol: truewhen the output is SOL. For SPL-to-SPL swaps, pass your input/output token account addresses. - Versioned transactions. With
txVersion: 'V0', Raydium returnsVersionedTransactions; deserialize, sign, and broadcast each through your node. The build can return more than one transaction (for example, when an account needs to be created first), so loop over all of them.
For on-chain control instead of the hosted API — building the swap locally, managing pool state, or working with a specific pool — use
@raydium-io/raydium-sdk-v2 and its raydium.cpmm.swap / raydium.liquidity.swap modules. See the raydium-sdk-V2-demo src/api/swap.ts (API path) and src/cpmm/swap.ts (on-chain path).Conclusion
Raydium’s Trade API gets you a working Solana swap with minimal code: it handles routing and pool selection, and hands you a transaction to sign and send through your own node. From here you can fix the output amount withswap-base-out, swap arbitrary SPL pairs by supplying token accounts, or drop down to @raydium-io/raydium-sdk-v2 when you need on-chain control. Pair it with a Chainstack Solana node for reliable, low-latency broadcasting.