跳轉到主要內容
POST
/
v2
/
dex
/
{chain}
/
route
Dex - 路由
curl --request POST \
  --url https://api.chainstream.io/v2/dex/{chain}/route \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "dex": "jupiter",
  "userAddress": "oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7",
  "amount": "1000000000",
  "swapMode": "ExactIn",
  "slippage": 5,
  "priorityFee": "1000",
  "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "outputMint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
  "recipientAddress": "0x0000000000000000000000000000000000000001",
  "permit": "66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9",
  "deadline": 1716806400000,
  "tipFee": "1000000",
  "isAntiMev": true,
  "maxFeePerGas": "50000000000",
  "maxPriorityFeePerGas": "2000000000",
  "gasPrice": "50000000000",
  "gasLimit": "300000"
}
'
import requests

url = "https://api.chainstream.io/v2/dex/{chain}/route"

payload = {
"dex": "jupiter",
"userAddress": "oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7",
"amount": "1000000000",
"swapMode": "ExactIn",
"slippage": 5,
"priorityFee": "1000",
"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"outputMint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
"recipientAddress": "0x0000000000000000000000000000000000000001",
"permit": "66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9",
"deadline": 1716806400000,
"tipFee": "1000000",
"isAntiMev": True,
"maxFeePerGas": "50000000000",
"maxPriorityFeePerGas": "2000000000",
"gasPrice": "50000000000",
"gasLimit": "300000"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dex: 'jupiter',
userAddress: 'oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7',
amount: '1000000000',
swapMode: 'ExactIn',
slippage: 5,
priorityFee: '1000',
inputMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
outputMint: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
recipientAddress: '0x0000000000000000000000000000000000000001',
permit: '66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9',
deadline: 1716806400000,
tipFee: '1000000',
isAntiMev: true,
maxFeePerGas: '50000000000',
maxPriorityFeePerGas: '2000000000',
gasPrice: '50000000000',
gasLimit: '300000'
})
};

fetch('https://api.chainstream.io/v2/dex/{chain}/route', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.chainstream.io/v2/dex/{chain}/route",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'dex' => 'jupiter',
'userAddress' => 'oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7',
'amount' => '1000000000',
'swapMode' => 'ExactIn',
'slippage' => 5,
'priorityFee' => '1000',
'inputMint' => 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
'outputMint' => 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
'recipientAddress' => '0x0000000000000000000000000000000000000001',
'permit' => '66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9',
'deadline' => 1716806400000,
'tipFee' => '1000000',
'isAntiMev' => true,
'maxFeePerGas' => '50000000000',
'maxPriorityFeePerGas' => '2000000000',
'gasPrice' => '50000000000',
'gasLimit' => '300000'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.chainstream.io/v2/dex/{chain}/route"

payload := strings.NewReader("{\n \"dex\": \"jupiter\",\n \"userAddress\": \"oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7\",\n \"amount\": \"1000000000\",\n \"swapMode\": \"ExactIn\",\n \"slippage\": 5,\n \"priorityFee\": \"1000\",\n \"inputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outputMint\": \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\",\n \"recipientAddress\": \"0x0000000000000000000000000000000000000001\",\n \"permit\": \"66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9\",\n \"deadline\": 1716806400000,\n \"tipFee\": \"1000000\",\n \"isAntiMev\": true,\n \"maxFeePerGas\": \"50000000000\",\n \"maxPriorityFeePerGas\": \"2000000000\",\n \"gasPrice\": \"50000000000\",\n \"gasLimit\": \"300000\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.chainstream.io/v2/dex/{chain}/route")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dex\": \"jupiter\",\n \"userAddress\": \"oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7\",\n \"amount\": \"1000000000\",\n \"swapMode\": \"ExactIn\",\n \"slippage\": 5,\n \"priorityFee\": \"1000\",\n \"inputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outputMint\": \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\",\n \"recipientAddress\": \"0x0000000000000000000000000000000000000001\",\n \"permit\": \"66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9\",\n \"deadline\": 1716806400000,\n \"tipFee\": \"1000000\",\n \"isAntiMev\": true,\n \"maxFeePerGas\": \"50000000000\",\n \"maxPriorityFeePerGas\": \"2000000000\",\n \"gasPrice\": \"50000000000\",\n \"gasLimit\": \"300000\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.chainstream.io/v2/dex/{chain}/route")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"dex\": \"jupiter\",\n \"userAddress\": \"oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7\",\n \"amount\": \"1000000000\",\n \"swapMode\": \"ExactIn\",\n \"slippage\": 5,\n \"priorityFee\": \"1000\",\n \"inputMint\": \"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\",\n \"outputMint\": \"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB\",\n \"recipientAddress\": \"0x0000000000000000000000000000000000000001\",\n \"permit\": \"66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9\",\n \"deadline\": 1716806400000,\n \"tipFee\": \"1000000\",\n \"isAntiMev\": true,\n \"maxFeePerGas\": \"50000000000\",\n \"maxPriorityFeePerGas\": \"2000000000\",\n \"gasPrice\": \"50000000000\",\n \"gasLimit\": \"300000\"\n}"

response = http.request(request)
puts response.read_body
{
  "args": {
    "dex": "jupiter",
    "userAddress": "oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7",
    "amount": "1000000000",
    "swapMode": "ExactIn",
    "slippage": 5,
    "priorityFee": "1000",
    "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "outputMint": "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
    "recipientAddress": "0x0000000000000000000000000000000000000001",
    "permit": "66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9",
    "deadline": 1716806400000,
    "tipFee": "1000000",
    "isAntiMev": true,
    "maxFeePerGas": "50000000000",
    "maxPriorityFeePerGas": "2000000000",
    "gasPrice": "50000000000",
    "gasLimit": "300000"
  },
  "serializedTx": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDRgYGpQEDAQIABQcICQoLDA0ODwAAAAAAAAAAAAAQERITFBUWFxgZGhscHR4fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
  "routeInfo": {
    "inAmount": "1000000000",
    "outAmount": "985000000",
    "priceImpact": "0.15",
    "route": [
      "USDC",
      "SOL"
    ]
  },
  "elapsedTime": 245,
  "recentBlockhash": "JE38e5sYDcpjcfuKA7Madpq8p3A4zc8UQuonCZDbn2yP",
  "lastValidBlockHeight": 416681972
}

授權

Authorization
string
header
必填

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

路徑參數

chain
enum<string>
必填

支援網路列表中的鏈名稱

可用選項:
sol,
bsc,
eth

主體

application/json
dex
enum<string>
必填

交易所使用的 DEX 標識符

可用選項:
jupiter,
kyberswap,
raydium,
pumpfun,
moonshot,
candy,
launchpad
範例:

"jupiter"

userAddress
string
必填

發起交易的錢包公鑰

Required string length: 8 - 64
範例:

"oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7"

amount
string
必填

兌換數量。使用 "auto" 表示全部餘額,或使用百分比如 "50%"

範例:

"1000000000"

swapMode
enum<string>
必填

兌換方向模式

可用選項:
ExactIn,
ExactOut
範例:

"ExactIn"

slippage
integer<int64>
預設值:5
必填

滑點容忍百分比

必填範圍: 0 <= x <= 100
範例:

5

priorityFee
string

優先費(SOL),用於提高交易處理速度

範例:

"1000"

inputMint
string

輸入代幣鑄造地址

範例:

"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"

outputMint
string

輸出代幣鑄造地址

範例:

"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"

recipientAddress
string

兌換的接收錢包地址

範例:

"0x0000000000000000000000000000000000000001"

permit
string

兌換的 Permit 資料

範例:

"66c85d1637257e890e581f724f69f4d4fc17eee156c0619c4719ed0c66eed0e9"

deadline
integer<int64>

兌換截止時間戳

範例:

1716806400000

tipFee
string

小費(SOL),用於提高交易處理速度

範例:

"1000000"

isAntiMev
boolean
預設值:false

是否啟用防 MEV 保護

範例:

true

maxFeePerGas
string

每 Gas 單位最大費用(EIP-1559),單位為 wei

範例:

"50000000000"

maxPriorityFeePerGas
string

每 Gas 單位最大優先費(EIP-1559),單位為 wei

範例:

"2000000000"

gasPrice
string

Gas 價格,單位為 wei(傳統交易)

範例:

"50000000000"

gasLimit
string

交易 Gas 上限

範例:

"300000"

回應

200 - application/json
args
object
必填

原始兌換請求參數

serializedTx
string
必填

Base64 編碼的交易

範例:

"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDRgYGpQEDAQIABQcICQoLDA0ODwAAAAAAAAAAAAAQERITFBUWFxgZGhscHR4fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

routeInfo
object
必填

詳細路由資訊

範例:
{
"inAmount": "1000000000",
"outAmount": "985000000",
"priceImpact": "0.15",
"route": ["USDC", "SOL"]
}
elapsedTime
integer<int64>
必填

請求處理耗時(毫秒)

範例:

245

recentBlockhash
string

兌換交易的最近區塊哈希

範例:

"JE38e5sYDcpjcfuKA7Madpq8p3A4zc8UQuonCZDbn2yP"

lastValidBlockHeight
integer<int64>

兌換交易的最後有效區塊高度

範例:

416681972