Get Solana Swap Instructions#
Obtain transaction instruction data for redemption or custom assembly in Solana.
Request URL#
GET https://web3.okx.com/api/v5/dex/aggregator/swap-instruction
Request Parameters#
Parameter | Type | Required | Description |
---|---|---|---|
chainIndex | String | Yes | Unique identifier for the chain. e.g., 501 : Solana. See more here. |
chainId | String | Yes | Unique identifier for the chain. It will be deprecated in the future. |
amount | String | Yes | Token amount for the quote. (The amount must include its precision. For example, exchanging 1.00 USDT requires inputting 1000000 , while exchanging 1.00 DAI requires 1000000000000000000 . Token precision can be obtained from the token list.) |
fromTokenAddress | String | Yes | Address of the token contract being swapped from (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ). |
toTokenAddress | String | Yes | Address of the token contract being swapped to (e.g., 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 ). |
slippage | String | Yes | Slippage limit. Note: On Solana, the minimum is 0 , and the maximum must be less than 1 .(e.g., 0.005 means a max slippage of 0.5% , 1 means 100% ). |
autoSlippage | Boolean | No | Default is false. When set to true, the original slippage (if set) will be covered by the autoSlippage and the API will calculate and return auto slippage recommendations based on current market data. |
maxAutoSlippage | String | No | When autoSlippage is set to true, this value is the maximum auto slippage returned by the API. We recommend that users adopt this value to ensure risk control. |
userWalletAddress | String | Yes | User’s wallet address (e.g., 0x3f6a3f57569358a512ccc0e513f171516b0fd42a ). |
swapReceiverAddress | String | No | Recipient address for the purchased asset. If not set, the asset will be sent to the userWalletAddress . (e.g., 0x3f6a3f57569358a512ccc0e513f171516b0fd42a ). |
feePercent | String | No | Percentage of the fromToken or toToken amount sent to the referral address. Minimum: 0% , Maximum: 10% , supports up to two decimal places (e.g., input 1.326% , but only 1.32% will be used). |
fromTokenReferrerWalletAddress | String | No | Wallet address receiving the referral fee in fromToken .Must be used with feePercent , and a single transaction can only apply either fromToken or toToken referral fees.Note: Solana: The referral address must hold some SOL for activation. |
toTokenReferrerWalletAddress | String | No | Wallet address receiving the referral fee in toToken .Must be used with feePercent , and a single transaction can only apply either fromToken or toToken referral fees.Note: Solana: The referral address must hold some SOL for activation. |
positiveSlippagePercent | String | No | Positive slippage represents the additional tokens received by the users above the quoted amount. By default, positive slippage is returned fully to the user. positiveSlippagePercent represents the maximum percentage of those additional tokens that can be retained by the integrator as revenue.Currently, this parameter is only supported on the Solana chain. For all other chains, any positive slippage will be fully returned to the user. The default setting is 0. Min percentage : 0 ,Max percentage : 10 , Maximum of 1 decimal point. |
positiveSlippageFeeAddress | string | No | The wallet address that receives positive slippage. You must set positiveSlippagePercent parameter together to specify the proportion. If provided, all positive slippage earnings will be sent to this address; if not provided, the wallet address used for collecting referral fees will be used instead. |
dexIds | String | No | Restrict the quote to specific liquidity pools by dexId . Multiple IDs should be comma-separated (e.g., 1,50,180 . See liquidity list for more details). |
directRoute | Boolean | No | The default setting is false. When enabled, Direct Routes restrict our routing to a single liquidity pool only. Currently, this feature is only active for Solana swaps. |
priceImpactProtectionPercentage | String | No | (Optional, default: 90% ) Allowed price impact percentage (between 0 and 1.0 ).If the estimated price impact exceeds the specified percentage, an error will be returned. Example: If priceImpactProtectionPercentage = 0.25 (25%) , any quote exceeding 25% price impact will return an error.This is an optional feature, defaulting to 0.9 . Setting it to 1.0 (100%) disables this protection, allowing all trades to proceed.Note: If price impact cannot be calculated, it will return null , and this feature will be disabled. |
computeUnitPrice | String | No | Used for transactions on the Solana network and similar to gasPrice on Ethereum. This price determines the priority level of the transaction. The higher the price, the more likely that the transaction can be processed faster. |
computeUnitLimit | String | No | Used for transactions on the Solana network and analogous to gasLimit on Ethereum, which ensures that the transaction won’t take too much computing resource. |
Response parameterseter#
Parameter | Type | Description |
---|---|---|
addressLookupTableAccount | Array | Address Lookup Table Account. A data structure in the Solana blockchain used to optimize the management and referencing of addresses in transactions. It allows developers to store a group of related addresses in a table and reference them in transactions via index values (instead of the full 32-byte address), significantly improving transaction efficiency and scalability. |
instructionLists | Array | Detailed transaction instruction information |
data | String | Instruction data |
accounts | Array | Instruction account information |
isSigner | Boolean | Whether the account is a signer |
isWritable | Boolean | Whether the account is writable |
pubkey | Boolean | Public key address of the account |
programId | String | Program ID for instruction execution |
routerResult | Object | Quote path data |
chainIndex | String | Unique identifier for the chain. |
chainId | String | Unique identifier for the chain. It will be deprecated in the future. |
swapMode | String | Swap mode of this quote. |
fromTokenAmount | String | The input amount of a token to be sold ( e.g.,500000000000000000000000 ) |
toTokenAmount | String | The resulting amount of a token to be bought ( e.g.,168611907733361 ) |
tradeFee | String | Estimated network fee (USD) of the quote route |
estimateGasFee | String | Estimated gas consumption is returned in the smallest units of each chain, such as wei. |
dexRouterList | Array | Quote path data set |
router | String | One of the main paths for the token swap |
routerPercent | String | The percentage of assets handled by the main path (e.g.,5 ) |
subRouterList | Array | Quote path sub data set |
dexProtocol | Array | Liquidity protocols used on the main path |
dexName | String | The name of the liquidity protocol (e.g.,Verse ) |
percent | String | The percentage of assets handled by the protocol (e.g.,100 ) |
fromToken | Object | The information of a token to be sold |
tokenContractAddress | String | Token contract address (e.g.,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 ) |
tokenSymbol | String | Token symbol (e.g.,USDC ) |
tokenUnitPrice | String | The token unit price returned by this interface is a general USDis a general USD real time price based on data from on-chain sources. Note: This price is only a recommended price. For some special cases, the token unit price may be 'null' |
decimal | String | The decimal number defines the smallest unit into which a single currency token can be divided. For example, if the decimal number of a token is 8, it means that a single such token can be divided into 100,000,000 of its smallest units. Note: This parameter is for reference only. It may change due to reasons such as settings adjustments by the contract owner. |
isHoneyPot | Boolean | If the token is a honeypot token. yes:true no:false |
taxRate | String | Token tax rate for selling: Applicable to tokens with configurable tax mechanisms (e.g., SafeMoon, SPL2022 tokens). Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%. |
toToken | Object | The information of a token to be bought |
tokenContractAddress | String | Token contract address (e.g.,0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48 ) |
tokenSymbol | String | Token symbol (e.g.,USDC ) |
tokenUnitPrice | String | The token unit price returned by this interface is a general USD price based on data from on-chain, exchange, and other third-party sources. Note: This price is only a recommended price. For some special cases, the token unit price may be 'null' |
decimal | String | The decimal number defines the smallest unit into which a single currency token can be divided. For example, if the decimal number of a token is 8, it means that a single such token can be divided into 100,000,000 of its smallest units. Note: This parameter is for reference only. It may change due to reasons such as settings adjustments by the contract owner. |
isHoneyPot | Boolean | If the token is a honeypot token. yes:true no:false |
taxRate | String | Token tax rate for buying: Applicable to tokens with configurable tax mechanisms (e.g., SafeMoon, SPL2022 tokens). Returns 0 for regular tokens without tax. The value ranges from 0 to 1, where 0.01 represents 1%. |
quoteCompareList | Array | Comparison of quote routes |
dexName | String | DEX name of the quote route |
dexLogo | String | DEX logo of the quote route |
tradeFee | String | Estimated network fee (USD) of the quote route |
amountOut | String | Received amount of the quote route |
priceImpactPercentage | String | Percentage = (Received value – Paid value) / Paid value. The swap amount will affect the depth of the liquidity pool, causing a value difference. This percentage can be positive if the received value exceeds the paid value. |
tx | Object | contract data model |
from | String | User's wallet address (e.g.,0x3f6a3f57569358a512ccc0e513f171516b0fd42a ) |
to | String | The contract address of OKX DEX router (e.g.,0x3b3ae790Df4F312e745D270119c6052904FB6790 ) |
minReceiveAmount | String | The minimum amount of a token to buy when the price reaches the upper limit of slippage (e.g.,900645839798 ) |
slippage | String | The value of current transaction slippage |
Request Example#
shell
curl --location --request GET 'https://web3.okx.com/api/v5/dex/aggregator/swap-instruction?chainIndex=501&amount=350000000&fromTokenAddress=11111111111111111111111111111111&toTokenAddress=Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB&slippage=0.4&userWalletAddress=FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk \
--header 'OK-ACCESS-KEY: 37c541a1-****-****-****-10fe7a038418' \
--header 'OK-ACCESS-SIGN: leaV********3uw=' \
--header 'OK-ACCESS-PASSPHRASE: 1****6' \
--header 'OK-ACCESS-TIMESTAMP: 2023-10-18T12:21:41.274Z'
Response Example#
200
{
"code": "0",
"data": {
"addressLookupTableAccount": [
"AUEghuJaUr4qshAQoSDvV8kfv7xz2kQGeR13G3FihMum",
"94jzMYK5NBoExhtdwzfVNVim6Y8b95JJ9xavKHGSns8R"
],
"instructionLists": [
{
"data": "AkCKAwA=",
"accounts": [],
"programId": "ComputeBudget111111111111111111111111111111"
},
{
"data": "A/EHCAAAAAAA",
"accounts": [],
"programId": "ComputeBudget111111111111111111111111111111"
},
{
"data": "AwAAAPwNLKvNGLxaIoVvQDDuyL46JSWpUG7CLB02dQ/9KzWaDQAAAAAAAAAxNzQ5MjU5NDU1OTU28B0fAAAAAAClAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp",
"accounts": [
{
"isSigner": true,
"isWritable": false,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
}
],
"programId": "11111111111111111111111111111111"
},
{
"data": "AQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "SysvarRent111111111111111111111111111111111"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"data": "AgAAAOAPlwAAAAAA",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
}
],
"programId": "11111111111111111111111111111111"
},
{
"data": "EQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"data": "AQ==",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "52WMDiGUj8UEzSzWjguGGnaWmnjeQobuB4qYdyKdmx4W"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "11111111111111111111111111111111"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
],
"programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
},
{
"data": "Rcj+9yg0dsrgD5cAAAAAACkhFgAAAAAA5wUVAAAAAAABAAAA4A+XAAAAAAABAAAAAQAAAAEAAAAiAQAAAGSAlpiAAAAAAAAhkAEAAAAAAA==",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "52WMDiGUj8UEzSzWjguGGnaWmnjeQobuB4qYdyKdmx4W"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "11111111111111111111111111111111"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"
},
{
"isSigner": true,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "52WMDiGUj8UEzSzWjguGGnaWmnjeQobuB4qYdyKdmx4W"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "ZiVoyhTDNKdceMF4Vt7X4VgSN9r8imBuJZRkUa9rWB7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "ADyA8hdefvWN2dbGGWFotbzWxrAvLW83WG6QCVXvJKqw"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "AAbcQKNDfbMxd7VRjK2x3UX3wQ4omoeNjAybrV89Ayx6"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9UgcBXUvLBuJkEHXhewVVCvrMtttUXQvbjm18z8ZT9Nf"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "62qc2CNXwrYqQScmEdiZFFAnJR262PxWEuNQtxfafNgV"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "94qWNrtmfn42h3ZjUZwWvK1MEo9uVmmrBPd2hpNjYDjb"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "11111111111111111111111111111111"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "GS4CU59F31iL7aR2Q8zVS8DRrcRnXX1yjQ66TqNVQnaR"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "Ei6iux5MMYG8JxCTr58goADqFTtMroL9TXJityF3fAQc"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "8N3GDaZ2iwN65oxVatKTLPNooAVUJTbfiVJ1ahyqwjSk"
}
],
"programId": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
},
{
"data": "CQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "DyWu8Q3aKuuDnzmgSBPGdczPsf5UixkJcGNr3zeyBqvW"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
},
{
"isSigner": true,
"isWritable": true,
"pubkey": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
],
"routerResult": {
"chainId": "501",
"chainIndex": "501",
"dexRouterList": [
{
"router": "11111111111111111111111111111111--es9vmfrzacermjfrf4h2fyd4kconky11mcce8benwnyb",
"routerPercent": "100",
"subRouterList": [
{
"dexProtocol": [
{
"dexName": "PumpSwap",
"percent": "100"
}
],
"fromToken": {
"decimal": "9",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "So11111111111111111111111111111111111111112",
"tokenSymbol": "wSOL",
"tokenUnitPrice": "148.133239619335163594"
},
"toToken": {
"decimal": "6",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"tokenSymbol": "USDT",
"tokenUnitPrice": "1.000673318734823276"
}
}
]
}
],
"estimateGasFee": "212000",
"fromToken": {
"decimal": "9",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "11111111111111111111111111111111",
"tokenSymbol": "SOL",
"tokenUnitPrice": "148.133239619335163594"
},
"fromTokenAmount": "10000000",
"priceImpactPercentage": "-1.04",
"quoteCompareList": [
{
"amountOut": "1.450281",
"dexLogo": "https://static.okx.com/cdn/web3/dex/logo/Pumpfun.png",
"dexName": "PumpSwap",
"tradeFee": "0.0000001571238"
}
],
"swapMode": "exactIn",
"toToken": {
"decimal": "6",
"isHoneyPot": false,
"taxRate": "0",
"tokenContractAddress": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"tokenSymbol": "USDT",
"tokenUnitPrice": "1.000673318734823276"
},
"toTokenAmount": "1450281",
"tradeFee": "0.00074115"
},
"tx": {
"from": "HxuPhmAYQwM4CvdJREL8ad3DgDWGVq4xBfy1vgGev5X7",
"minReceiveAmount": "1377767",
"slippage": "0.05",
"to": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
}
},
"msg": ""
}