Saros SDK on Solana Devnet – Quick Start & Tutorials

This guide shows how to use the Saros TypeScript/JavaScript SDK (@saros-finance/sdk) on Solana’s Devnet. We cover environment setup, wallet generation and funding, connecting to Devnet, swapping tokens, adding liquidity, and staking LP tokens (with reward claiming). All steps include code samples (Node.js) and references to official docs or guides. Short paragraphs and lists make it easy to scan; each key statement cites a source.

Environment Setup

Wallet Setup

Fetch AMM Pools

Initialize the Saros AMM client and fetch available pools:

const amm = new SarosAMM(connection, wallet);
const pools = await amm.getPools();
console.log("Found AMM pools:", pools);

This returns an array of pool objects (address, token mints, etc.). For example:

for (const pool of pools) {
  console.log(`Pool ${pool.address}: tokens = ${pool.tokenA.symbol}-${pool.tokenB.symbol}`);
}

Make sure you have SOL (Devnet) in the wallet before querying or swapping. You may want to try/catch these calls to handle errors (e.g. network issues).

Perform a Token Swap

Once you have a funded wallet and know the pool addresses and token mints, you can swap tokens. For example, to swap 1 SOL → USDC:

const SOL_MINT = new PublicKey("So11111111111111111111111111111111111111112");  // Wrapped SOL
const USDC_MINT = new PublicKey("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"); // Official Devnet USDC

try {
  const swapSig = await amm.swap({
    poolAddress: pools[0].address,  // pick a suitable pool from getPools()
    fromMint: SOL_MINT,
    toMint: USDC_MINT,
    amountIn: 1 * LAMPORTS_PER_SOL, // 1 SOL
    slippage: 0.5                  // 0.5% tolerance
  });
  console.log("Swap tx signature:", swapSig);
  console.log(`Explorer: https://explorer.solana.com/tx/${swapSig}?cluster=devnet`);
} catch (err) {
  console.error("Swap failed:", err);
}

This is similar to Saros's example. For your convenience, it logs the transaction signature. On Devnet, use the explorer URL with ?cluster=devnet. If you see an “invalid pool” error or swap failure, first check that the pool address matches the token mints. If the price moved significantly, increase the slippage (e.g. to 1.0%). Also, ensure you’re using at least "confirmed" commitment (default above) and have enough SOL for fees.