What this does. Loads a CPMM pool from RPC, quotes a swap with 0.5% slippage, builds the transaction, signs with your keypair, and submits it. End-to-end in ~30 lines.
Setup
Make sure you’ve read the Quick start prerequisites and haveRPC_URL, KEYPAIR, and the deps installed.
The script
Save asswap.mjs:
Run it
Pick any CPMM pool you have liquidity for. Example with the canonical SOL/USDC CPMM pool:What just happened
Raydium.loadinitialised the SDK — fetched the global config, set up your wallet context.getPoolInfoFromRpcpulled the live pool state directly from RPC (not from the API cache). For high-value swaps you always want fresh state.CurveCalculator.swapcomputed the constant-product output net of the pool’s fee. This is the same math the program runs on-chain, so you can compare quotes off- and on-chain.raydium.cpmm.swapbuilt the transaction with V0 format (address lookup tables enabled) and added an explicit compute-budget config. The compute-budget tip helps the tx land in busy windows.execute({ sendAndConfirm: true })signed, sent, and waited for confirmation.
Common errors
Pool not found— WrongPOOL_ID, or you’re pointed at the wrong cluster (mainnet pool ID against a devnet RPC, etc.).Insufficient funds for transaction— Your wallet doesn’t have enough SOL for the swap input + fees + ATA rent.Slippage tolerance exceeded— The pool’s price moved between quote and execution. Re-run; or raise theslippageparameter; or use the SDK’scomputeAmountOutwhich always re-fetches reserves.Token account not initialized— Output token’s ATA didn’t exist and the implicit-create instruction landed but failed for some reason; check your wallet’s SOL balance and try again.
Next
sdk-api/typescript-sdk— full SDK reference.products/cpmm/instructions— what the swap instruction looks like on-chain.integration-guides/priority-fee-tuning— sizingcomputeBudgetConfigfor production.

