How to execute a swap
In this section, you'll learn how to request ready-to-use transaction data for executing a token swap on Solana.
Prerequisites
As in the How to Get a Quote section, you can choose either the explicit path or the protocol-agnostic (less explicit) path to get the transaction data.
A) Protocol-Specific Approach (Explicit)
Use this when you want to work with a specific Solana AMM protocol (e.g., Raydium, Orca).
Request Transaction Data Fetch specific protocol information using:
GET /strategies/:id/bytecode
Required Parameters:
ParameterDescriptionExampleaction
Type of operation
swap
protocol
Protocol name
raydium
fromToken
Token mint to swap from
So11111111111111111111111111111111111111112
(Wrapped SOL)toToken
Token mint to swap to
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
(USDC)amountIn
Input amount in lamports
1000000000
(1 SOL)minAmountOut
Minimum output with slippage
25000000
(25 USDC)slippage
Maximum price slippage
0.5
(0.5% slippage tolerance)userPubkey
User's wallet public key
7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU
Example Request:
GET /strategies/raydium-sol-usdc/bytecode?action=swap&protocol=raydium&fromToken=So11111111111111111111111111111111111111112&toToken=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amountIn=1000000000&minAmountOut=25000000&slippage=0.5&userPubkey=7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU
Response:
{ "transaction": { "instructions": [ { "programId": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8", "data": "2U5yRTWAyasvNpVi89HF8g1ZHeB6HmFiSuLqwvDkbKaQJzcaFzefnGg8VaB9Nz", "keys": [ { "pubkey": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU", "isSigner": true, "isWritable": true }, // ... other account keys ] } ], "recentBlockhash": "GHtXQBsoZHVnNFa9YhE4YHNSjkb7jZbSEHUEPPTHBQz7", "feePayer": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU" }, "signers": [] }
B) Protocol-Agnostic Approach (Less Explicit)
Let our system automatically select the optimal AMM protocol for your swap.
Use the Generic Endpoint
GET /strategies/0x0/bytecode
Use the same parameters as above, excluding
protocol
.Example Request:
GET /strategies/0x0/bytecode?action=swap&fromToken=So11111111111111111111111111111111111111112&toToken=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&amountIn=1000000000&minAmountOut=25000000&slippage=0.5&userPubkey=7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU
Execute the Transaction
The transaction needs to be signed and submitted to the Solana network. This happens on your end - we don't touch your funds, custody remains yours.
Here's a basic example using @solana/web3.js:
import { Connection, Transaction } from '@solana/web3.js';
// 1. Create a connection to the network
const connection = new Connection('https://api.mainnet-beta.solana.com');
// 2. Convert the received transaction data
const transaction = Transaction.from(Buffer.from(response.transaction));
// 3. Sign the transaction (using your preferred wallet adapter)
const signedTx = await wallet.signTransaction(transaction);
// 4. Send the signed transaction
const signature = await connection.sendRawTransaction(signedTx.serialize());
// 5. Confirm the transaction
await connection.confirmTransaction(signature);

Next Steps
After executing the swap, you can:
Important Notes
Always ensure you have enough SOL for transaction fees
Check that you have Associated Token Accounts (ATAs) created for the tokens
The API will automatically handle ATA creation if needed
Transaction data includes all necessary setup instructions (ATA creation, token approvals)
Slippage protection is crucial due to Solana's fast block times
Last updated