li-fi-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

LI.FI REST API Integration

LI.FI REST API 集成

The LI.FI REST API provides direct HTTP access to cross-chain swap and bridge functionality. Use this API when building backend services, working with non-JavaScript languages, or needing fine-grained control over cross-chain operations.
LI.FI REST API 提供跨链兑换与桥接功能的直接HTTP访问。当你构建后端服务、使用非JavaScript语言,或需要对跨链操作进行精细化控制时,可使用此API。

Base URL

基础URL

https://li.quest/v1
https://li.quest/v1

Authentication

身份验证

API key is optional but recommended for higher rate limits.
bash
undefined
API密钥为可选,但使用它可获得更高的请求速率限制。
bash
undefined

Without API key (lower rate limits)

不使用API密钥(较低速率限制)

With API key (higher rate limits)

使用API密钥(较高速率限制)

curl "https://li.quest/v1/chains"
-H "x-lifi-api-key: YOUR_API_KEY"

**Important**: Never expose your API key in client-side code. Use it only in server-side applications.
curl "https://li.quest/v1/chains"
-H "x-lifi-api-key: YOUR_API_KEY"

**重要提示**:绝不要在客户端代码中暴露你的API密钥,仅在服务器端应用中使用。

Rate Limits

速率限制

TierLimit
Without API keyPer IP address
With API keyPer API key
Request an API key from LI.FI for production use with higher limits.
层级限制规则
无API密钥基于IP地址
有API密钥基于API密钥
如需在生产环境中使用更高的速率限制,请向LI.FI申请API密钥。

Quick Start

快速开始

1. Get a Quote

1. 获取报价

bash
curl "https://li.quest/v1/quote?\
fromChain=42161&\
toChain=10&\
fromToken=0xaf88d065e77c8cC2239327C5EDb3A432268e5831&\
toToken=0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1&\
fromAmount=10000000&\
fromAddress=0xYourAddress&\
slippage=0.005"
bash
curl "https://li.quest/v1/quote?\
fromChain=42161&\
toChain=10&\
fromToken=0xaf88d065e77c8cC2239327C5EDb3A432268e5831&\
toToken=0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1&\
fromAmount=10000000&\
fromAddress=0xYourAddress&\
slippage=0.005"

2. Execute the Transaction

2. 执行交易

Use the
transactionRequest
from the quote response to send the transaction via your wallet or web3 library.
使用报价响应中的
transactionRequest
,通过你的钱包或web3库发送交易。

3. Track Status

3. 追踪状态

bash
curl "https://li.quest/v1/status?\
txHash=0xYourTxHash&\
fromChain=42161&\
toChain=10&\
bridge=stargate"
bash
curl "https://li.quest/v1/status?\
txHash=0xYourTxHash&\
fromChain=42161&\
toChain=10&\
bridge=stargate"

Core Endpoints

核心接口

GET /quote

GET /quote

Get a single-step quote with transaction data ready for execution.
Parameters:
ParameterTypeRequiredDescription
fromChain
numberYesSource chain ID
toChain
numberYesDestination chain ID
fromToken
stringYesSource token address
toToken
stringYesDestination token address
fromAmount
stringYesAmount in smallest unit
fromAddress
stringYesSender wallet address
toAddress
stringNoRecipient address
slippage
numberNoSlippage tolerance (0.005 = 0.5%)
integrator
stringNoYour integrator ID
allowBridges
string[]NoAllowed bridges (or
all
,
none
,
default
)
denyBridges
string[]NoDenied bridges
preferBridges
string[]NoPreferred bridges
allowExchanges
string[]NoAllowed exchanges (or
all
,
none
,
default
)
denyExchanges
string[]NoDenied exchanges
preferExchanges
string[]NoPreferred exchanges
allowDestinationCall
booleanNoAllow contract calls on destination (default: true)
order
stringNoRoute preference:
FASTEST
or
CHEAPEST
fee
numberNoIntegrator fee (0.02 = 2%, max <100%)
referrer
stringNoReferrer tracking information
fromAmountForGas
stringNoAmount to convert to gas on destination
maxPriceImpact
numberNoMax price impact threshold (0.1 = 10%, default: 10%)
skipSimulation
booleanNoSkip TX simulation for faster response
swapStepTimingStrategies
string[]NoTiming strategy for swap rates
routeTimingStrategies
string[]NoTiming strategy for route selection
Example Request:
bash
curl "https://li.quest/v1/quote?\
fromChain=1&\
toChain=137&\
fromToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&\
toToken=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174&\
fromAmount=1000000000&\
fromAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&\
slippage=0.005"
The response includes
transactionRequest
with all data needed to execute the swap. See references/REFERENCE.md for complete response schema.
获取包含可直接执行交易数据的单步报价。
参数:
参数类型是否必填描述
fromChain
数字源链ID
toChain
数字目标链ID
fromToken
字符串源代币地址
toToken
字符串目标代币地址
fromAmount
字符串最小单位的代币数量
fromAddress
字符串发送方钱包地址
toAddress
字符串接收方地址
slippage
数字滑点容忍度(0.005 = 0.5%)
integrator
字符串你的集成商ID
allowBridges
字符串数组允许使用的桥接工具(可选值:
all
none
default
denyBridges
字符串数组禁止使用的桥接工具
preferBridges
字符串数组优先使用的桥接工具
allowExchanges
字符串数组允许使用的交易所(可选值:
all
none
default
denyExchanges
字符串数组禁止使用的交易所
preferExchanges
字符串数组优先使用的交易所
allowDestinationCall
布尔值是否允许在目标链上调用合约(默认:true)
order
字符串路线偏好:
FASTEST
(最快)或
CHEAPEST
(最便宜)
fee
数字集成商手续费(0.02 = 2%,最大值<100%)
referrer
字符串推荐人追踪信息
fromAmountForGas
字符串转换为目标链Gas的代币数量
maxPriceImpact
数字最大价格影响阈值(0.1 = 10%,默认:10%)
skipSimulation
布尔值跳过交易模拟以加快响应速度
swapStepTimingStrategies
字符串数组兑换汇率的时间策略
routeTimingStrategies
字符串数组路线选择的时间策略
示例请求:
bash
curl "https://li.quest/v1/quote?\
fromChain=1&\
toChain=137&\
fromToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&\
toToken=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174&\
fromAmount=1000000000&\
fromAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&\
slippage=0.005"
响应包含
transactionRequest
,其中包含执行兑换所需的所有数据。完整响应架构请参考references/REFERENCE.md

POST /advanced/routes

POST /advanced/routes

Get multiple route options for comparison. Returns routes without transaction data (use
/advanced/stepTransaction
to get TX data for a specific step).
Request Body:
json
{
  "fromChainId": 42161,
  "toChainId": 10,
  "fromTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  "toTokenAddress": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
  "fromAmount": "10000000",
  "fromAddress": "0xYourAddress",
  "options": {
    "integrator": "YourAppName",
    "slippage": 0.005,
    "order": "CHEAPEST",
    "bridges": {
      "allow": ["stargate", "hop", "across"]
    },
    "exchanges": {
      "allow": ["1inch", "uniswap"]
    },
    "allowSwitchChain": true,
    "maxPriceImpact": 0.1
  }
}
Example Request:
bash
curl -X POST "https://li.quest/v1/advanced/routes" \
  -H "Content-Type: application/json" \
  -d '{
    "fromChainId": 42161,
    "toChainId": 10,
    "fromTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
    "toTokenAddress": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
    "fromAmount": "10000000",
    "options": {
      "slippage": 0.005,
      "integrator": "YourApp"
    }
  }'
Returns array of routes sorted by
order
preference. Each route contains
steps
but no
transactionRequest
- use
/advanced/stepTransaction
to get TX data.
获取多个路线选项用于对比。返回的路线不包含交易数据(需使用
/advanced/stepTransaction
获取特定步骤的交易数据)。
请求体:
json
{
  "fromChainId": 42161,
  "toChainId": 10,
  "fromTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  "toTokenAddress": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
  "fromAmount": "10000000",
  "fromAddress": "0xYourAddress",
  "options": {
    "integrator": "YourAppName",
    "slippage": 0.005,
    "order": "CHEAPEST",
    "bridges": {
      "allow": ["stargate", "hop", "across"]
    },
    "exchanges": {
      "allow": ["1inch", "uniswap"]
    },
    "allowSwitchChain": true,
    "maxPriceImpact": 0.1
  }
}
示例请求:
bash
curl -X POST "https://li.quest/v1/advanced/routes" \
  -H "Content-Type: application/json" \
  -d '{
    "fromChainId": 42161,
    "toChainId": 10,
    "fromTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
    "toTokenAddress": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
    "fromAmount": "10000000",
    "options": {
      "slippage": 0.005,
      "integrator": "YourApp"
    }
  }'
返回按
order
偏好排序的路线数组。每条路线包含
steps
但无
transactionRequest
- 需使用
/advanced/stepTransaction
获取交易数据。

POST /advanced/stepTransaction

POST /advanced/stepTransaction

Populate a step (from
/advanced/routes
) with transaction data. Use this after selecting a route to get the actual transaction to execute.
Request Body: Send the full
Step
object from a route.
Query Parameters:
ParameterTypeRequiredDescription
skipSimulation
booleanNoSkip TX simulation for faster response
Example:
bash
curl -X POST "https://li.quest/v1/advanced/stepTransaction" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "step-id",
    "type": "cross",
    "tool": "stargate",
    "action": {...},
    "estimate": {...}
  }'
Response: Returns the Step object with
transactionRequest
populated.
为(来自
/advanced/routes
的)步骤填充交易数据。选择路线后,使用此接口获取可执行的实际交易。
请求体: 发送路线中的完整
Step
对象。
查询参数:
参数类型是否必填描述
skipSimulation
布尔值跳过交易模拟以加快响应速度
示例:
bash
curl -X POST "https://li.quest/v1/advanced/stepTransaction" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "step-id",
    "type": "cross",
    "tool": "stargate",
    "action": {...},
    "estimate": {...}
  }'
响应: 返回已填充
transactionRequest
的Step对象。

GET /status

GET /status

Track transaction status across chains. Can query by sending TX hash, receiving TX hash, or transactionId.
Parameters:
ParameterTypeRequiredDescription
txHash
stringYesTransaction hash (sending, receiving, or transactionId)
fromChain
numberNoSource chain ID (speeds up request)
toChain
numberNoDestination chain ID
bridge
stringNoBridge tool name
For same-chain swaps, set
fromChain
and
toChain
to the same value.
Example Request:
bash
curl "https://li.quest/v1/status?txHash=0x123abc..."
Response includes:
transactionId
,
sending
(txHash, amount, chainId),
receiving
(txHash, amount, chainId),
status
,
substatus
,
lifiExplorerLink
.
Status Values:
NOT_FOUND
,
INVALID
,
PENDING
,
DONE
,
FAILED
Poll until status is
DONE
or
FAILED
. See references/REFERENCE.md for complete substatus values.
跨链追踪交易状态。可通过发送交易哈希、接收交易哈希或transactionId进行查询。
参数:
参数类型是否必填描述
txHash
字符串交易哈希(发送方、接收方或transactionId)
fromChain
数字源链ID(可加快请求速度)
toChain
数字目标链ID
bridge
字符串桥接工具名称
对于同链兑换,将
fromChain
toChain
设置为相同值。
示例请求:
bash
curl "https://li.quest/v1/status?txHash=0x123abc..."
响应包含:
transactionId
sending
(txHash、数量、chainId)、
receiving
(txHash、数量、chainId)、
status
substatus
lifiExplorerLink
状态值:
NOT_FOUND
(未找到)、
INVALID
(无效)、
PENDING
(处理中)、
DONE
(完成)、
FAILED
(失败)
轮询直到状态变为
DONE
FAILED
。完整子状态值请参考references/REFERENCE.md

GET /chains

GET /chains

Get all supported chains.
Parameters:
ParameterTypeRequiredDescription
chainTypes
stringNoFilter by chain types:
EVM
,
SVM
bash
curl "https://li.quest/v1/chains"
curl "https://li.quest/v1/chains?chainTypes=EVM,SVM"
获取所有支持的链。
参数:
参数类型是否必填描述
chainTypes
字符串按链类型过滤:
EVM
SVM
bash
curl "https://li.quest/v1/chains"
curl "https://li.quest/v1/chains?chainTypes=EVM,SVM"

GET /tokens

GET /tokens

Get tokens for specified chains.
Parameters:
ParameterTypeRequiredDescription
chains
stringNoComma-separated chain IDs or keys (e.g.,
POL,DAI
)
chainTypes
stringNoFilter by chain types:
EVM
,
SVM
minPriceUSD
numberNoMin token price filter (default: 0.0001 USD)
bash
curl "https://li.quest/v1/tokens?chains=1,137,42161"
获取指定链的代币列表。
参数:
参数类型是否必填描述
chains
字符串逗号分隔的链ID或标识(例如:
POL,DAI
chainTypes
字符串按链类型过滤:
EVM
SVM
minPriceUSD
数字代币最低价格过滤(默认:0.0001 USD)
bash
curl "https://li.quest/v1/tokens?chains=1,137,42161"

GET /token

GET /token

Get information about a specific token.
Parameters:
ParameterTypeRequiredDescription
chain
stringYesChain ID or key (e.g.,
POL
or
137
)
token
stringYesToken address or symbol (e.g.,
DAI
)
bash
curl "https://li.quest/v1/token?chain=POL&token=DAI"
获取特定代币的信息。
参数:
参数类型是否必填描述
chain
字符串链ID或标识(例如:
POL
137
token
字符串代币地址或符号(例如:
DAI
bash
curl "https://li.quest/v1/token?chain=POL&token=DAI"

GET /tools

GET /tools

Get available bridges and exchanges. Use this to discover valid tool keys for filtering quotes.
Parameters:
ParameterTypeRequiredDescription
chains
stringNoFilter by chain IDs
bash
curl "https://li.quest/v1/tools"
curl "https://li.quest/v1/tools?chains=1,137"
Returns
bridges
and
exchanges
arrays with
key
,
name
, and
supportedChains
. Use these keys in
allowBridges
,
denyBridges
,
allowExchanges
, etc.
Special values:
all
,
none
,
default
,
[]
获取可用的桥接工具和交易所。使用此接口发现用于过滤报价的有效工具标识。
参数:
参数类型是否必填描述
chains
字符串按链ID过滤
bash
curl "https://li.quest/v1/tools"
curl "https://li.quest/v1/tools?chains=1,137"
返回包含
bridges
exchanges
的数组,每个元素包含
key
name
supportedChains
。可将这些标识用于
allowBridges
denyBridges
allowExchanges
等参数中。
特殊值:
all
none
default
[]

GET /connections

GET /connections

Get available token pair connections. At least one filter (chain, token, bridge, or exchange) is required.
Parameters:
ParameterTypeRequiredDescription
fromChain
stringNoSource chain ID or key
toChain
stringNoDestination chain ID or key
fromToken
stringNoSource token address or symbol
toToken
stringNoDestination token address or symbol
chainTypes
stringNoFilter by chain types:
EVM,SVM
allowBridges
string[]NoAllowed bridges
denyBridges
string[]NoDenied bridges
preferBridges
string[]NoPreferred bridges
allowExchanges
string[]NoAllowed exchanges
denyExchanges
string[]NoDenied exchanges
preferExchanges
string[]NoPreferred exchanges
allowSwitchChain
booleanNoInclude routes requiring chain switch (default: true)
allowDestinationCall
booleanNoInclude routes with destination calls (default: true)
bash
curl "https://li.quest/v1/connections?\
fromChain=POL&\
fromToken=DAI"
获取可用的代币对连接。至少需要一个过滤条件(链、代币、桥接工具或交易所)。
参数:
参数类型是否必填描述
fromChain
字符串源链ID或标识
toChain
字符串目标链ID或标识
fromToken
字符串源代币地址或符号
toToken
字符串目标代币地址或符号
chainTypes
字符串按链类型过滤:
EVM,SVM
allowBridges
字符串数组允许使用的桥接工具
denyBridges
字符串数组禁止使用的桥接工具
preferBridges
字符串数组优先使用的桥接工具
allowExchanges
字符串数组允许使用的交易所
denyExchanges
字符串数组禁止使用的交易所
preferExchanges
字符串数组优先使用的交易所
allowSwitchChain
布尔值是否包含需要切换链的路线(默认:true)
allowDestinationCall
布尔值是否包含目标链有合约调用的路线(默认:true)
bash
curl "https://li.quest/v1/connections?\
fromChain=POL&\
fromToken=DAI"

POST /quote/contractCalls

POST /quote/contractCalls

Get a quote for bridging tokens and performing multiple contract calls on the destination chain. This enables 1-click DeFi workflows like bridge + swap + deposit.
Request Body:
json
{
  "fromChain": 10,
  "fromToken": "0x4200000000000000000000000000000000000042",
  "fromAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
  "toChain": 1,
  "toToken": "ETH",
  "toAmount": "100000000000001",
  "integrator": "YourAppName",
  "contractCalls": [
    {
      "fromAmount": "100000000000001",
      "fromTokenAddress": "0x0000000000000000000000000000000000000000",
      "toTokenAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toContractAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toContractCallData": "0x",
      "toContractGasLimit": "110000"
    },
    {
      "fromAmount": "100000000000000",
      "fromTokenAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toTokenAddress": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
      "toContractAddress": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
      "toFallbackAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
      "toContractCallData": "0xea598cb000000000000000000000000000000000000000000000000000005af3107a4000",
      "toContractGasLimit": "100000"
    }
  ]
}
获取桥接代币并在目标链执行多笔合约调用的报价。此接口支持一键式DeFi工作流,例如桥接+兑换+存入。
请求体:
json
{
  "fromChain": 10,
  "fromToken": "0x4200000000000000000000000000000000000042",
  "fromAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
  "toChain": 1,
  "toToken": "ETH",
  "toAmount": "100000000000001",
  "integrator": "YourAppName",
  "contractCalls": [
    {
      "fromAmount": "100000000000001",
      "fromTokenAddress": "0x0000000000000000000000000000000000000000",
      "toTokenAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toContractAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toContractCallData": "0x",
      "toContractGasLimit": "110000"
    },
    {
      "fromAmount": "100000000000000",
      "fromTokenAddress": "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
      "toTokenAddress": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
      "toContractAddress": "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
      "toFallbackAddress": "0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0",
      "toContractCallData": "0xea598cb000000000000000000000000000000000000000000000000000005af3107a4000",
      "toContractGasLimit": "100000"
    }
  ]
}

Integration Examples

集成示例

Python

Python

python
import requests

BASE_URL = "https://li.quest/v1"

def get_quote(from_chain, to_chain, from_token, to_token, amount, address):
    response = requests.get(f"{BASE_URL}/quote", params={
        "fromChain": from_chain,
        "toChain": to_chain,
        "fromToken": from_token,
        "toToken": to_token,
        "fromAmount": amount,
        "fromAddress": address,
        "slippage": 0.005
    })
    return response.json()

def get_status(tx_hash, from_chain, to_chain, bridge):
    response = requests.get(f"{BASE_URL}/status", params={
        "txHash": tx_hash,
        "fromChain": from_chain,
        "toChain": to_chain,
        "bridge": bridge
    })
    return response.json()
python
import requests

BASE_URL = "https://li.quest/v1"

def get_quote(from_chain, to_chain, from_token, to_token, amount, address):
    response = requests.get(f"{BASE_URL}/quote", params={
        "fromChain": from_chain,
        "toChain": to_chain,
        "fromToken": from_token,
        "toToken": to_token,
        "fromAmount": amount,
        "fromAddress": address,
        "slippage": 0.005
    })
    return response.json()

def get_status(tx_hash, from_chain, to_chain, bridge):
    response = requests.get(f"{BASE_URL}/status", params={
        "txHash": tx_hash,
        "fromChain": from_chain,
        "toChain": to_chain,
        "bridge": bridge
    })
    return response.json()

Example usage

示例用法

quote = get_quote( from_chain=42161, to_chain=10, from_token="0xaf88d065e77c8cC2239327C5EDb3A432268e5831", to_token="0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", amount="10000000", address="0xYourAddress" )
print(f"Estimated output: {quote['estimate']['toAmount']}") print(f"Gas cost: {quote['estimate']['gasCosts']}")
undefined
quote = get_quote( from_chain=42161, to_chain=10, from_token="0xaf88d065e77c8cC2239327C5EDb3A432268e5831", to_token="0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", amount="10000000", address="0xYourAddress" )
print(f"预估输出: {quote['estimate']['toAmount']}") print(f"Gas成本: {quote['estimate']['gasCosts']}")
undefined

Node.js (fetch)

Node.js (fetch)

javascript
const BASE_URL = 'https://li.quest/v1';

async function getQuote(params) {
  const searchParams = new URLSearchParams(params);
  const response = await fetch(`${BASE_URL}/quote?${searchParams}`);
  return response.json();
}

async function getRoutes(body) {
  const response = await fetch(`${BASE_URL}/routes`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  return response.json();
}

async function pollStatus(txHash, fromChain, toChain, bridge) {
  const params = new URLSearchParams({ txHash, fromChain, toChain, bridge });
  
  while (true) {
    const response = await fetch(`${BASE_URL}/status?${params}`);
    const data = await response.json();
    
    if (data.status === 'DONE' || data.status === 'FAILED') {
      return data;
    }
    
    await new Promise(resolve => setTimeout(resolve, 5000));
  }
}

// Example usage
const quote = await getQuote({
  fromChain: 42161,
  toChain: 10,
  fromToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
  toToken: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
  fromAmount: '10000000',
  fromAddress: '0xYourAddress',
  slippage: 0.005,
});
javascript
const BASE_URL = 'https://li.quest/v1';

async function getQuote(params) {
  const searchParams = new URLSearchParams(params);
  const response = await fetch(`${BASE_URL}/quote?${searchParams}`);
  return response.json();
}

async function getRoutes(body) {
  const response = await fetch(`${BASE_URL}/routes`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });
  return response.json();
}

async function pollStatus(txHash, fromChain, toChain, bridge) {
  const params = new URLSearchParams({ txHash, fromChain, toChain, bridge });
  
  while (true) {
    const response = await fetch(`${BASE_URL}/status?${params}`);
    const data = await response.json();
    
    if (data.status === 'DONE' || data.status === 'FAILED') {
      return data;
    }
    
    await new Promise(resolve => setTimeout(resolve, 5000));
  }
}

// 示例用法
const quote = await getQuote({
  fromChain: 42161,
  toChain: 10,
  fromToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
  toToken: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
  fromAmount: '10000000',
  fromAddress: '0xYourAddress',
  slippage: 0.005,
});

Error Handling

错误处理

HTTP StatusDescription
200Success
400Bad request - check parameters
429Rate limit exceeded - wait or use API key
500Internal error - retry
See references/REFERENCE.md for complete error codes and response schemas.
HTTP状态码描述
200请求成功
400请求参数错误 - 检查参数
429请求速率超限 - 等待或使用API密钥
500服务器内部错误 - 重试
完整错误码和响应架构请参考references/REFERENCE.md

Best Practices

最佳实践

  1. Always specify slippage - Default is conservative. Adjust based on token volatility.
  2. Poll status endpoint - For cross-chain transfers, poll every 5-10 seconds until
    DONE
    or
    FAILED
    .
  3. Handle rate limits - Implement exponential backoff for 429 responses.
  4. Cache chain/token data -
    /chains
    and
    /tokens
    responses change infrequently.
  5. Use integrator parameter - Always include
    integrator
    for analytics and potential monetization.
  6. Validate addresses - Ensure token addresses match the specified chain.
  7. Handle gas estimation - The API provides gas estimates, but actual costs may vary.
See references/REFERENCE.md for complete endpoint documentation and response schemas.
  1. 始终指定滑点 - 默认滑点设置较为保守,可根据代币波动性调整。
  2. 轮询状态接口 - 对于跨链转账,每5-10秒轮询一次,直到状态变为
    DONE
    FAILED
  3. 处理速率限制 - 针对429响应实现指数退避策略。
  4. 缓存链/代币数据 -
    /chains
    /tokens
    的响应更新频率较低。
  5. 使用integrator参数 - 始终包含
    integrator
    参数,以便进行数据分析和潜在的变现。
  6. 验证地址 - 确保代币地址与指定链匹配。
  7. 处理Gas预估 - API提供Gas预估,但实际成本可能有所不同。
完整接口文档和响应架构请参考references/REFERENCE.md