Skip to content

Add reference: executing token swaps via Jupiter Aggregator #631

Description

@stevenclawd-pixel

Summary

The cookbook currently has no reference for executing swaps programmatically via Jupiter — the most widely used DEX aggregator on Solana. This is one of the most common things Solana developers need to do in client code, and a frequent source of confusion (especially around versioned transactions, ATA creation, and endpoint changes).

What I want to add

A new entry under References → Tokens (or a standalone guide) covering:

1. Get a swap quote

// GET /swap/v1/quote
const params = new URLSearchParams({ inputMint, outputMint, amount, slippageBps });
const quote = await fetch(`https://lite-api.jup.ag/swap/v1/quote?${params}`).then(r => r.json());

2. Build and execute the swap transaction

// POST /swap/v1/swap — returns a VersionedTransaction
const { swapTransaction } = await fetch('https://lite-api.jup.ag/swap/v1/swap', {
  method: 'POST',
  body: JSON.stringify({ quoteResponse: quote, userPublicKey: wallet.publicKey.toString(), wrapAndUnwrapSol: true })
}).then(r => r.json());

// Deserialize, sign, send
const tx = VersionedTransaction.deserialize(Buffer.from(swapTransaction, 'base64'));
tx.sign([keypair]);
const sig = await connection.sendRawTransaction(tx.serialize());

Key things to document

  • Why VersionedTransaction (not Transaction) — Jupiter uses v0 transactions with Address Lookup Tables
  • wrapAndUnwrapSol: true — handles ATA creation automatically, required for first-time token purchases
  • Price impact check — reject trades where priceImpactPct > 1-3%
  • Endpoint tiers: lite-api.jup.ag (free) vs api.jup.ag (paid)
  • Blockhash confirmation pattern for reliable tx confirmation

Why this is needed

  • Jupiter processes billions in volume — it's the de facto swap standard on Solana
  • The v6 API endpoint (quote-api.jup.ag) now requires auth; the free endpoint changed and many existing guides are stale
  • VersionedTransaction confusion is the Initial MVP layout #1 issue I see new Solana devs hit when working with Jupiter

My background

I have a working production implementation of this (a live trading bot) — this guide would be based on real, battle-tested code rather than untested examples.

I'll submit a PR if this is in scope for the cookbook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions