Skip to main content

Executing Swaps

This guide walks through the full swap lifecycle using the Argyros API on Fogo.

Flow

  1. Get a quote. Find the best route and estimated output.
  2. Build a transaction. Get an unsigned transaction from the API.
  3. Sign. Sign the transaction with the user’s wallet.
  4. Submit. Send the signed transaction to the network.
  5. Confirm. Wait for on-chain confirmation.

Step 1: Get a quote

curl "https://api.argyros.xyz/api/v1/quote?\
inputMint=So11111111111111111111111111111111111111112&\
outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&\
amount=1000000000&\
swapMode=ExactIn&\
slippageBps=50"

Step 2: Build the swap transaction

curl -X POST "https://api.argyros.xyz/api/v1/swap" \
  -H "Content-Type: application/json" \
  -d '{
    "userWallet": "YOUR_WALLET_ADDRESS",
    "inputMint": "So11111111111111111111111111111111111111112",
    "outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "amount": "1000000000",
    "swapMode": "ExactIn",
    "slippageBps": 50
  }'

Step 3: Sign and submit

TypeScript
import { Connection, VersionedTransaction } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");

const txBuffer = Buffer.from(swap.data.transaction, "base64");
const transaction = VersionedTransaction.deserialize(txBuffer);

transaction.sign([wallet]);

const signature = await connection.sendRawTransaction(transaction.serialize(), {
  skipPreflight: false,
  maxRetries: 3,
});

const confirmation = await connection.confirmTransaction({
  signature,
  blockhash: transaction.message.recentBlockhash,
  lastValidBlockHeight: swap.data.lastValidBlockHeight,
});

if (confirmation.value.err) {
  throw new Error(`Transaction failed: ${JSON.stringify(confirmation.value.err)}`);
}

console.log(`Swap confirmed: https://solscan.io/tx/${signature}`);

Using raw instructions instead

If you need to compose swap instructions with other instructions (e.g., creating token accounts, adding memos), use POST /instructions instead of POST /swap. See the Get Instructions endpoint.