/swap-instructions REST API Endpoint - Metis
Please note that this method is available for Free and Paid subscribers of Metis - Jupiter Swap API, along with jupiterapi.com users.
Solana Kit includes the ability to customize RPC methods and transports, allowing you to seamlessly integrate Quicknode Marketplace add-ons into your applications. For more information on how to use Quicknode Marketplace add-ons with Solana Kit, check out these guides: How to Use Quicknode Add-ons using Solana Kit (Part 1) and How to Use Quicknode Add-ons using Solana Kit (Part 2)
GooseFX Gamma API: When using the /quote endpoint with the setting of dexes=Gamma, you should include the query parameter dexes=Gamma when using this endpoint if you want to route directly to the GooseFX Gamma API. This is in addition to setting dexes=Gamma on your initial /quote request.
查询参数
userPublicKey
字符串
必填
正在加载...
payer
字符串
正在加载...
wrapAndUnwrapSol
布尔型
正在加载...
useSharedAccounts
布尔型
正在加载...
feeAccount
字符串
正在加载...
trackingAccount
字符串
正在加载...
computeUnitPriceMicroLamports
整数
正在加载...
prioritizationFeeLamports
对象
正在加载...
priorityLevelWithMaxLamports
对象
正在加载...
priorityLevel
字符串
正在加载...
maxLamports
整数
正在加载...
global
布尔型
正在加载...
jitoTipLamports
整数
正在加载...
jitoTipLamportsWithPayer
对象
正在加载...
lamports
整数
必填
正在加载...
payer
字符串
必填
正在加载...
asLegacyTransaction
布尔型
正在加载...
destinationTokenAccount
字符串
正在加载...
nativeDestinationAccount
字符串
正在加载...
dynamicComputeUnitLimit
布尔型
正在加载...
skipUserAccountsRpcCalls
布尔型
正在加载...
dynamicSlippage
布尔型
正在加载...
blockhashSlotsToExpiry
整数
正在加载...
quoteResponse
对象
必填
正在加载...
inputMint
字符串
必填
正在加载...
inAmount
字符串
必填
正在加载...
outputMint
字符串
必填
正在加载...
outAmount
字符串
必填
正在加载...
otherAmountThreshold
字符串
必填
正在加载...
swapMode
字符串
必填
正在加载...
slippageBps
整数
必填
正在加载...
platformFee
对象
正在加载...
金额
字符串
正在加载...
feeBps
整数
正在加载...
priceImpactPct
字符串
必填
正在加载...
routePlan
数组
必填
正在加载...
swapInfo
对象
必填
正在加载...
ammKey
字符串
必填
正在加载...
标签
字符串
正在加载...
inputMint
字符串
必填
正在加载...
outputMint
字符串
必填
正在加载...
inAmount
字符串
必填
正在加载...
outAmount
字符串
必填
正在加载...
feeAmount
字符串
必填
正在加载...
feeMint
字符串
必填
正在加载...
percent
整数
必填
正在加载...
bps
整数
正在加载...
instructionVersion
字符串
正在加载...
contextSlot
整数
正在加载...
timeTaken
整数
正在加载...
退货
tokenLedgerInstruction
对象
正在加载...
programId
字符串
正在加载...
accounts
数组
正在加载...
公钥
字符串
正在加载...
isSigner
布尔型
正在加载...
isWritable
布尔型
正在加载...
数据
字符串
正在加载...
computeBudgetInstructions
数组
正在加载...
programId
字符串
正在加载...
accounts
数组
正在加载...
公钥
字符串
正在加载...
isSigner
布尔型
正在加载...
isWritable
布尔型
正在加载...
数据
字符串
正在加载...
setupInstructions
数组
正在加载...
programId
字符串
正在加载...
accounts
数组
正在加载...
公钥
字符串
正在加载...
isSigner
布尔型
正在加载...
isWritable
布尔型
正在加载...
数据
字符串
正在加载...
swapInstruction
对象
正在加载...
programId
字符串
正在加载...
accounts
数组
正在加载...
公钥
字符串
正在加载...
isSigner
布尔型
正在加载...
isWritable
布尔型
正在加载...
数据
字符串
正在加载...
cleanupInstruction
对象
正在加载...
programId
字符串
正在加载...
accounts
数组
正在加载...
公钥
字符串
正在加载...
isSigner
布尔型
正在加载...
isWritable
布尔型
正在加载...
数据
字符串
正在加载...
otherInstructions
数组
正在加载...
addressLookupTableAddresses
数组
正在加载...
prioritizationFeeLamports
整数
正在加载...
请求
1curl --location 'https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions' \2--header 'Content-Type: application/json' \3--data '{4"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",5"quoteResponse": {6"inputMint": "So11111111111111111111111111111111111111112",7"inAmount": "1000000000",8"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",9"outAmount": "47737119",10"otherAmountThreshold": "47498434",11"swapMode": "ExactIn",12"slippageBps": 50,13"platformFee": null,14"priceImpactPct": "0",15"routePlan": [16{17"swapInfo": {18"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",19"label": "Phoenix",20"inputMint": "So11111111111111111111111111111111111111112",21"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",22"inAmount": "200000000",23"outAmount": "9546224",24"feeAmount": "4776",25"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"26},27"percent": 2028},29{30"swapInfo": {31"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",32"label": "Meteora DLMM",33"inputMint": "So11111111111111111111111111111111111111112",34"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",35"inAmount": "800000000",36"outAmount": "59167218",37"feeAmount": "240003",38"feeMint": "So11111111111111111111111111111111111111112"39},40"percent": 8041},42{43"swapInfo": {44"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",45"label": "Whirlpool",46"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",47"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",48"inAmount": "59167218",49"outAmount": "148627676",50"feeAmount": "0",51"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"52},53"percent": 10054},55{56"swapInfo": {57"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",58"label": "Phoenix",59"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",60"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",61"inAmount": "148627676",62"outAmount": "38190895",63"feeAmount": "19105",64"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"65},66"percent": 10067}68],69"contextSlot": 257193413,70"timeTaken": 0.41189167771}72}'
1curl --location 'https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions' \2--header 'Content-Type: application/json' \3--data '{4"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",5"quoteResponse": {6"inputMint": "So11111111111111111111111111111111111111112",7"inAmount": "1000000000",8"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",9"outAmount": "47737119",10"otherAmountThreshold": "47498434",11"swapMode": "ExactIn",12"slippageBps": 50,13"platformFee": null,14"priceImpactPct": "0",15"routePlan": [16{17"swapInfo": {18"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",19"label": "Phoenix",20"inputMint": "So11111111111111111111111111111111111111112",21"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",22"inAmount": "200000000",23"outAmount": "9546224",24"feeAmount": "4776",25"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"26},27"percent": 2028},29{30"swapInfo": {31"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",32"label": "Meteora DLMM",33"inputMint": "So11111111111111111111111111111111111111112",34"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",35"inAmount": "800000000",36"outAmount": "59167218",37"feeAmount": "240003",38"feeMint": "So11111111111111111111111111111111111111112"39},40"percent": 8041},42{43"swapInfo": {44"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",45"label": "Whirlpool",46"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",47"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",48"inAmount": "59167218",49"outAmount": "148627676",50"feeAmount": "0",51"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"52},53"percent": 10054},55{56"swapInfo": {57"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",58"label": "Phoenix",59"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",60"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",61"inAmount": "148627676",62"outAmount": "38190895",63"feeAmount": "19105",64"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"65},66"percent": 10067}68],69"contextSlot": 257193413,70"timeTaken": 0.41189167771}72}'
1require "uri"2require "json"3require "net/http"45url = URI("https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions")67https = Net::HTTP.new(url.主机, url.端口)8https.use_ssl = true910请求 = Net::HTTP::POST.new(url)11请求["Content-Type"] = "application/json"12请求.请求体 = JSON.dump({13"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",14"quoteResponse": {15"inputMint": "So11111111111111111111111111111111111111112",16"inAmount": "1000000000",17"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",18"outAmount": "47737119",19"otherAmountThreshold": "47498434",20"swapMode": "ExactIn",21"slippageBps": 50,22"platformFee": nil,23"priceImpactPct": "0",24"routePlan": [25{26"swapInfo": {27"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",28"label": "Phoenix",29"inputMint": "So11111111111111111111111111111111111111112",30"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",31"inAmount": "200000000",32"outAmount": "9546224",33"feeAmount": "4776",34"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"35},36"percent": 2037},38{39"swapInfo": {40"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",41"label": "Meteora DLMM",42"inputMint": "So11111111111111111111111111111111111111112",43"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",44"inAmount": "800000000",45"outAmount": "59167218",46"feeAmount": "240003",47"feeMint": "So11111111111111111111111111111111111111112"48},49"percent": 8050},51{52"swapInfo": {53"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",54"label": "Whirlpool",55"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",56"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",57"inAmount": "59167218",58"outAmount": "148627676",59"feeAmount": "0",60"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"61},62"percent": 10063},64{65"swapInfo": {66"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",67"label": "Phoenix",68"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",69"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",70"inAmount": "148627676",71"outAmount": "38190895",72"feeAmount": "19105",73"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"74},75"percent": 10076}77],78"contextSlot": 257193413,79"timeTaken": 0.41189167780}81})8283回复 = https.请求(请求)84返回响应.read_body85
1require "uri"2require "json"3require "net/http"45url = URI("https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions")67https = Net::HTTP.new(url.主机, url.端口)8https.use_ssl = true910请求 = Net::HTTP::POST.new(url)11请求["Content-Type"] = "application/json"12请求.请求体 = JSON.dump({13"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",14"quoteResponse": {15"inputMint": "So11111111111111111111111111111111111111112",16"inAmount": "1000000000",17"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",18"outAmount": "47737119",19"otherAmountThreshold": "47498434",20"swapMode": "ExactIn",21"slippageBps": 50,22"platformFee": nil,23"priceImpactPct": "0",24"routePlan": [25{26"swapInfo": {27"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",28"label": "Phoenix",29"inputMint": "So11111111111111111111111111111111111111112",30"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",31"inAmount": "200000000",32"outAmount": "9546224",33"feeAmount": "4776",34"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"35},36"percent": 2037},38{39"swapInfo": {40"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",41"label": "Meteora DLMM",42"inputMint": "So11111111111111111111111111111111111111112",43"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",44"inAmount": "800000000",45"outAmount": "59167218",46"feeAmount": "240003",47"feeMint": "So11111111111111111111111111111111111111112"48},49"percent": 8050},51{52"swapInfo": {53"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",54"label": "Whirlpool",55"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",56"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",57"inAmount": "59167218",58"outAmount": "148627676",59"feeAmount": "0",60"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"61},62"percent": 10063},64{65"swapInfo": {66"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",67"label": "Phoenix",68"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",69"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",70"inAmount": "148627676",71"outAmount": "38190895",72"feeAmount": "19105",73"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"74},75"percent": 10076}77],78"contextSlot": 257193413,79"timeTaken": 0.41189167780}81})8283回复 = https.请求(请求)84返回响应.read_body85
1const myHeaders = new Headers();2myHeaders.追加("Content-Type", "application/json");34const raw = JSON.stringify({5"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",6"quoteResponse": {7"inputMint": "So11111111111111111111111111111111111111112",8"inAmount": "1000000000",9"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",10"outAmount": "47737119",11"otherAmountThreshold": "47498434",12"swapMode": "ExactIn",13"slippageBps": 50,14"platformFee": null,15"priceImpactPct": "0",16"routePlan": [17{18"swapInfo": {19"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",20"label": "Phoenix",21"inputMint": "So11111111111111111111111111111111111111112",22"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",23"inAmount": "200000000",24"outAmount": "9546224",25"feeAmount": "4776",26"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"27},28"percent": 2029},30{31"swapInfo": {32"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",33"label": "Meteora DLMM",34"inputMint": "So11111111111111111111111111111111111111112",35"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",36"inAmount": "800000000",37"outAmount": "59167218",38"feeAmount": "240003",39"feeMint": "So11111111111111111111111111111111111111112"40},41"percent": 8042},43{44"swapInfo": {45"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",46"label": "Whirlpool",47"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",48"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",49"inAmount": "59167218",50"outAmount": "148627676",51"feeAmount": "0",52"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"53},54"percent": 10055},56{57"swapInfo": {58"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",59"label": "Phoenix",60"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",61"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",62"inAmount": "148627676",63"outAmount": "38190895",64"feeAmount": "19105",65"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"66},67"percent": 10068}69],70"contextSlot": 257193413,71"timeTaken": 0.41189167772}73});7475const requestOptions = {76方法: "POST",77标题: myHeaders,78正文: raw,79重定向: "follow"80};8182fetch("https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions", requestOptions)83.然后((响应) => 响应.文本())84.然后((结果) => 控制台.log(result))85.catch((error) => 控制台.错误(error));
1const myHeaders = new Headers();2myHeaders.追加("Content-Type", "application/json");34const raw = JSON.stringify({5"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",6"quoteResponse": {7"inputMint": "So11111111111111111111111111111111111111112",8"inAmount": "1000000000",9"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",10"outAmount": "47737119",11"otherAmountThreshold": "47498434",12"swapMode": "ExactIn",13"slippageBps": 50,14"platformFee": null,15"priceImpactPct": "0",16"routePlan": [17{18"swapInfo": {19"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",20"label": "Phoenix",21"inputMint": "So11111111111111111111111111111111111111112",22"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",23"inAmount": "200000000",24"outAmount": "9546224",25"feeAmount": "4776",26"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"27},28"percent": 2029},30{31"swapInfo": {32"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",33"label": "Meteora DLMM",34"inputMint": "So11111111111111111111111111111111111111112",35"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",36"inAmount": "800000000",37"outAmount": "59167218",38"feeAmount": "240003",39"feeMint": "So11111111111111111111111111111111111111112"40},41"percent": 8042},43{44"swapInfo": {45"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",46"label": "Whirlpool",47"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",48"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",49"inAmount": "59167218",50"outAmount": "148627676",51"feeAmount": "0",52"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"53},54"percent": 10055},56{57"swapInfo": {58"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",59"label": "Phoenix",60"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",61"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",62"inAmount": "148627676",63"outAmount": "38190895",64"feeAmount": "19105",65"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"66},67"percent": 10068}69],70"contextSlot": 257193413,71"timeTaken": 0.41189167772}73});7475const requestOptions = {76方法: "POST",77标题: myHeaders,78正文: raw,79重定向: "follow"80};8182fetch("https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions", requestOptions)83.然后((响应) => 响应.文本())84.然后((结果) => 控制台.log(result))85.catch((error) => 控制台.错误(error));
1import { QuoteGetRequest, QuoteResponse, createJupiterApiClient, ResponseError } from '@jup-ag/api';2import { Keypair } from '@solana/web3.js';34const ENDPOINT = `https://docs-demo.solana-mainnet.quiknode.pro/`;5const CONFIG = {6basePath: ENDPOINT7};89const quoteRequest: QuoteGetRequest = {10inputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",11outputMint: "So11111111111111111111111111111111111111112",12amount: 10.03 * 1e6,13}1415async function main(): Promise<void> {16const jupiterApi = createJupiterApiClient(CONFIG);17const wallet = Keypair.generate();1819try {20// 1. Retrieve a Swap Quote21const quote: QuoteResponse | null = await jupiterApi.quoteGet(quoteRequest);22if (!quote) {23throw new Error('No quote found');24}2526// 2. Get Serialized Swap Transaction27const swapResult = await jupiterApi.swapInstructionsPost({28swapRequest: {29//@ts-ignore30quoteResponse: quote,31userPublicKey: wallet.publicKey.toBase58(),32},33});34if (!swapResult) {35throw new Error('No swap result found');36}37console.log(swapResult);38} catch (error) {39if (error instanceof ResponseError) {40console.log(await error.response.json());41}42else {43console.error(error);44}45}46}4748主();
1import { QuoteGetRequest, QuoteResponse, createJupiterApiClient, ResponseError } from '@jup-ag/api';2import { Keypair } from '@solana/web3.js';34const ENDPOINT = `https://docs-demo.solana-mainnet.quiknode.pro/`;5const CONFIG = {6basePath: ENDPOINT7};89const quoteRequest: QuoteGetRequest = {10inputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",11outputMint: "So11111111111111111111111111111111111111112",12amount: 10.03 * 1e6,13}1415async function main(): Promise<void> {16const jupiterApi = createJupiterApiClient(CONFIG);17const wallet = Keypair.generate();1819try {20// 1. Retrieve a Swap Quote21const quote: QuoteResponse | null = await jupiterApi.quoteGet(quoteRequest);22if (!quote) {23throw new Error('No quote found');24}2526// 2. Get Serialized Swap Transaction27const swapResult = await jupiterApi.swapInstructionsPost({28swapRequest: {29//@ts-ignore30quoteResponse: quote,31userPublicKey: wallet.publicKey.toBase58(),32},33});34if (!swapResult) {35throw new Error('No swap result found');36}37console.log(swapResult);38} catch (error) {39if (error instanceof ResponseError) {40console.log(await error.response.json());41}42else {43console.error(error);44}45}46}4748主();
1#[tokio::main]2async fn main() -> Result<(), Box<dyn std::error::Error>> {3let client = reqwest::Client::builder()4.build()?;56let mut headers = reqwest::header::HeaderMap::new();7headers.insert("Content-Type", "application/json".parse()?);89let data = r#"{10"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",11"quoteResponse": {12"inputMint": "So11111111111111111111111111111111111111112",13"inAmount": "1000000000",14"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",15"outAmount": "47737119",16"otherAmountThreshold": "47498434",17"swapMode": "ExactIn",18"slippageBps": 50,19"platformFee": null,20"priceImpactPct": "0",21"routePlan": [22{23"swapInfo": {24"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",25"label": "Phoenix",26"inputMint": "So11111111111111111111111111111111111111112",27"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",28"inAmount": "200000000",29"outAmount": "9546224",30"feeAmount": "4776",31"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"32},33"percent": 2034},35{36"swapInfo": {37"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",38"label": "Meteora DLMM",39"inputMint": "So11111111111111111111111111111111111111112",40"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",41"inAmount": "800000000",42"outAmount": "59167218",43"feeAmount": "240003",44"feeMint": "So11111111111111111111111111111111111111112"45},46"percent": 8047},48{49"swapInfo": {50"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",51"label": "Whirlpool",52"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",53"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",54"inAmount": "59167218",55"outAmount": "148627676",56"feeAmount": "0",57"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"58},59"percent": 10060},61{62"swapInfo": {63"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",64"label": "Phoenix",65"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",66"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",67"inAmount": "148627676",68"outAmount": "38190895",69"feeAmount": "19105",70"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"71},72"percent": 10073}74],75"contextSlot": 257193413,76"timeTaken": 0.41189167777}78}"#;7980let json: serde_json::Value = serde_json::from_str(&data)?;8182let request = client.request(reqwest::Method::POST, "https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions")83.标题(标题))84.json(&json);8586let response = request.send().await?;87let 正文 = 响应.text().await?;8889println!("{}", body);9091好的(())92}
1#[tokio::main]2async fn main() -> Result<(), Box<dyn std::error::Error>> {3let client = reqwest::Client::builder()4.build()?;56let mut headers = reqwest::header::HeaderMap::new();7headers.insert("Content-Type", "application/json".parse()?);89let data = r#"{10"userPublicKey": "3gqQQT8KS6sDLUzHGbBDweg5bT1g443eMSDkKgwGzRdM",11"quoteResponse": {12"inputMint": "So11111111111111111111111111111111111111112",13"inAmount": "1000000000",14"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",15"outAmount": "47737119",16"otherAmountThreshold": "47498434",17"swapMode": "ExactIn",18"slippageBps": 50,19"platformFee": null,20"priceImpactPct": "0",21"routePlan": [22{23"swapInfo": {24"ammKey": "BKLhZ5NrFhCjViC4wyAMXBNsJFHbFfYujo3TtUmBxTH3",25"label": "Phoenix",26"inputMint": "So11111111111111111111111111111111111111112",27"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",28"inAmount": "200000000",29"outAmount": "9546224",30"feeAmount": "4776",31"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"32},33"percent": 2034},35{36"swapInfo": {37"ammKey": "G7ixPyiyNeggVf1VanSetFMNbVuVCPtimJmd9axfQqng",38"label": "Meteora DLMM",39"inputMint": "So11111111111111111111111111111111111111112",40"outputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",41"inAmount": "800000000",42"outAmount": "59167218",43"feeAmount": "240003",44"feeMint": "So11111111111111111111111111111111111111112"45},46"percent": 8047},48{49"swapInfo": {50"ammKey": "BCuk3J7Djjn6WYzSBWrHyGM2cgpUeBBHQtxskgiqyv7p",51"label": "Whirlpool",52"inputMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4",53"outputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",54"inAmount": "59167218",55"outAmount": "148627676",56"feeAmount": "0",57"feeMint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4"58},59"percent": 10060},61{62"swapInfo": {63"ammKey": "6ojSigXF7nDPyhFRgmn3V9ywhYseKF9J32ZrranMGVSX",64"label": "Phoenix",65"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",66"outputMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm",67"inAmount": "148627676",68"outAmount": "38190895",69"feeAmount": "19105",70"feeMint": "EKpQGSJtjMFqKZ9KQanSqYXRcF8fBopzLHYxdM65zcjm"71},72"percent": 10073}74],75"contextSlot": 257193413,76"timeTaken": 0.41189167777}78}"#;7980let json: serde_json::Value = serde_json::from_str(&data)?;8182let request = client.request(reqwest::Method::POST, "https://docs-demo.solana-mainnet.quiknode.pro/swap-instructions")83.标题(标题))84.json(&json);8586let response = request.send().await?;87let 正文 = 响应.text().await?;8889println!("{}", body);9091好的(())92}