Get Solana swap instructions#
Obtain transaction instruction data for redemption or custom assembly in Solana.
Request address#
GET https://www.okx.com/api/v5/dex/aggregator/swap-instruction
Request parameters#
Parameter | Type | Required | Description |
---|---|---|---|
chainId | String | Yes | Chain ID (e.g., 1 for Ethereum. See Chain ID List for more details.) |
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% ). |
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: 3% , 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. |
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). |
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 parameter#
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 |
Request example#
shell
curl --location --request GET 'https://www.okx.com/api/v5/dex/aggregator/swap-instruction?chainId=501&amount=350000000&fromTokenAddress=11111111111111111111111111111111&toTokenAddress=Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB&slippage=0.4&userWalletAddress=FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk \
--header 'OK-ACCESS-PROJECT: 86af********d1bc' \
--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": {
"addressLookupTableAddresses": [
"EDDSpjZHrsFKYTMJDcBqXAjkLcu9EKdvrQR4XnqsXErH",
"9YcB7FUV4cLxTtDWEf399ooy3idpfepeEhMqGihKDDwX",
"4tbRdGdVvuSzWjFeJJYVMv2vvTpEhCdWbFmNZAnuxmtk"
],
"instructionLists": [
{
"data": "ApC+BgA=",
"accounts": [],
"programId": "ComputeBudget111111111111111111111111111111"
},
{
"data": "A08vKAAAAAAA",
"accounts": [],
"programId": "ComputeBudget111111111111111111111111111111"
},
{
"data": "AwAAAN22LW+lIkpOjB6e81eI68Mgzu7zEfkmh9QEBkCPOLG3DQAAAAAAAAAxNzM5MjU1OTc3NzU58B0fAAAAAAClAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCp",
"accounts": [
{
"isSigner": true,
"isWritable": false,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
}
],
"programId": "11111111111111111111111111111111"
},
{
"data": "AQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "SysvarRent111111111111111111111111111111111"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"data": "AgAAAICT3BQAAAAA",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
}
],
"programId": "11111111111111111111111111111111"
},
{
"data": "EQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"data": "AQ==",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HwEh3U3E7aPRwXUhzes6wxX1kbSmKm85ugK6DXP5vgzf"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "11111111111111111111111111111111"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
],
"programId": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
},
{
"data": "QUs/TOtbW4iAk9wUAAAAAIXrRQQAAAAAHVqQAgAAAAABAAAAgJPcFAAAAAABAAAAAgAAAAEAAAANAQAAAGQBAAAABQEAAABkTpgBAAAAAAA=",
"accounts": [
{
"isSigner": true,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HwEh3U3E7aPRwXUhzes6wxX1kbSmKm85ugK6DXP5vgzf"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
},
{
"isSigner": true,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HjkGLCPnsMr4yP2Tmi1Uj7gV7Y2xDj2Npn9kYfVBYr2s"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "8gJ7UWboMeQ6z6AQwFP3cAZwSYG8udVS2UesyCbH79r7"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "chM5ZB1uPZxvJJAK4D1Z4KHAYjWKvwuQTy6fFAeWQ1T"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "FGFaiYjXTVuLsKvzn6ueckraNTeqUGHeYqrQPQCpd7kH"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "So11111111111111111111111111111111111111112"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "DoBNfRox1ZjEsZq6QPY4jpN8hN4Fu9JVkAxJQro164VR"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "D1ZN9Wj1fRSUQfCjhvnu1hqDMT7hzjzBBpi12nVniYD6"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "6TWKYuLYtuJVtvfqnPEs1ZxFMRDGTKkQJgTa4Dv7CzQS"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "EMfT8Jw2M5fs691J6ycgTuggXRJ4uLfbCrqZYJXMXpdL"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "7VVeicGxT7XmwG4Sg25QVFRcAZDaBtGxT9d1CpByzGYN"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HjkGLCPnsMr4yP2Tmi1Uj7gV7Y2xDj2Npn9kYfVBYr2s"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "HwEh3U3E7aPRwXUhzes6wxX1kbSmKm85ugK6DXP5vgzf"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "2EXiumdi14E9b8Fy62QcA5Uh6WdHS2b38wtSxp72Mibj"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "3uaZBfHPfmpAHW7dsimC1SnyR61X4bJqQZKWmRSCXJxv"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "4zbGjjRx8bmZjynJg2KnkJ54VAk1crcrYsGMy79EXK1P"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "5XkWQL9FJL4qEvL8c3zCzzWnMGzerM3jbGuuyRprsEgG"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "jfrmNrBtxnX1FH36ATeiaXnpA4ppQcKtv7EfrgMsgLJ"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "77quYg4MGneUdjgXCunt9GgM1usmrxKY31twEy3WHwcS"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "37m9QdvxmKRdjm3KKV2AjTiGcXMfWHQpVFnmhtb289yo"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "AQKXXC29ybqL8DLeAVNt3ebpwMv8Sb4csberrP6Hz6o5"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9MgPMkdEHFX7DZaitSh6Crya3kCCr1As6JC75bm3mjuC"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "H61Y7xVnbWVXrQQx3EojTEqf3ogKVY5GfGjEn5ewyX7B"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "9FLih4qwFMjdqRAGmHeCxa64CgjP1GtcgKJgHHgz44ar"
},
{
"isSigner": false,
"isWritable": false,
"pubkey": "FGBvMAu88q9d1Csz7ZECB5a2gbWwp6qicNxN2Mo7QhWG"
}
],
"programId": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma"
},
{
"data": "CQ==",
"accounts": [
{
"isSigner": false,
"isWritable": true,
"pubkey": "9haFKThJYWEVA66mtxv7nTBWMHieQdnZpmLjvXAiS2zm"
},
{
"isSigner": false,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
},
{
"isSigner": true,
"isWritable": true,
"pubkey": "FvUDkjR1STZ3c6g3DjXwLsiQ477t2HGH4LQ81xMKWJZk"
}
],
"programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
}
]
},
"msg": ""
}