Solana Swap Transaction Instructions: API Reference Guide

ยท

Introduction

This guide explains how to retrieve transaction instruction data for executing swaps or price quotes on the Solana blockchain through our DEX Aggregator API.

API Endpoint

GET https://web3.okx.com/api/v5/dex/aggregator/swap-instruction

Request Parameters

ParameterTypeRequiredDescription
chainIndexStringYesChain identifier (e.g., 501 for Solana)
chainIdStringYesChain identifier (deprecated)
amountStringYesToken amount with decimals (e.g., 1000000 for 1.00 USDT)
fromTokenAddressStringYesSource token contract address
toTokenAddressStringYesDestination token contract address
slippageStringYesMaximum slippage tolerance (0 to <1 for Solana)
autoSlippageBooleanNoEnable automatic slippage calculation
maxAutoSlippageStringNoMaximum auto-slippage limit when enabled
userWalletAddressStringYesUser's wallet address
swapReceiverAddressStringNoAlternate recipient address for swapped tokens
feePercentStringNoCommission percentage (0-10%)
fromTokenReferrerWalletAddressStringNoCommission wallet for source token
toTokenReferrerWalletAddressStringNoCommission wallet for destination token
positiveSlippagePercentStringNoPositive slippage capture percentage (Solana only)
positiveSlippageFeeAddressStringNoWallet for positive slippage fees
dexIdsStringNoComma-separated liquidity pool IDs
directRouteBooleanNoRestrict to single liquidity pool routes
priceImpactProtectionPercentageStringNoMaximum allowed price impact (0-1.0)
computeUnitPriceStringNoSolana transaction priority fee
computeUnitLimitStringNoSolana computation resource limit

Response Parameters

ParameterTypeDescription
addressLookupTableAccountArraySolana address lookup table
instructionListsArrayTransaction instructions
routerResultObjectPrice quote route data
dexRouterListArrayExchange route percentages
fromTokenObjectSource token details
toTokenObjectDestination token details
quoteCompareListArrayPrice comparison data
txObjectTransaction information

๐Ÿ‘‰ Learn more about Solana transaction optimization

Key Features

  1. Multi-DEX Aggregation: Combines liquidity from multiple decentralized exchanges
  2. Slippage Protection: Customizable slippage tolerance levels
  3. Fee Optimization: Calculates optimal network fees
  4. Route Comparison: Shows best available swap paths

Best Practices

FAQ

What is the minimum slippage for Solana swaps?

The minimum slippage is 0%, but we recommend at least 0.1% for most transactions.

How do I calculate token amounts with decimals?

Multiply the desired token quantity by 10^decimals. For example, 1 USDC (6 decimals) = 1000000.

๐Ÿ‘‰ Need help with Solana transactions?

What happens if my transaction exceeds the price impact protection?

The API will return an error if the estimated price impact exceeds your specified protection percentage.

Can I specify which DEXs to use?

Yes, use the dexIds parameter to limit liquidity sources.

Conclusion

This API provides comprehensive tools for executing efficient swaps on Solana, with features designed to optimize pricing, minimize fees, and protect against unfavorable market conditions. Always review the response data carefully before signing transactions.

๐Ÿ‘‰ Explore advanced DEX features