li-fi-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLI.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/v1https://li.quest/v1Authentication
身份验证
API key is optional but recommended for higher rate limits.
bash
undefinedAPI密钥为可选,但使用它可获得更高的请求速率限制。
bash
undefinedWithout API key (lower rate limits)
不使用API密钥(较低速率限制)
curl "https://li.quest/v1/chains"
curl "https://li.quest/v1/chains"
With API key (higher rate limits)
使用API密钥(较高速率限制)
curl "https://li.quest/v1/chains"
-H "x-lifi-api-key: YOUR_API_KEY"
-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"
-H "x-lifi-api-key: YOUR_API_KEY"
**重要提示**:绝不要在客户端代码中暴露你的API密钥,仅在服务器端应用中使用。Rate Limits
速率限制
| Tier | Limit |
|---|---|
| Without API key | Per IP address |
| With API key | Per 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 from the quote response to send the transaction via your wallet or web3 library.
transactionRequest使用报价响应中的,通过你的钱包或web3库发送交易。
transactionRequest3. 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| number | Yes | Source chain ID |
| number | Yes | Destination chain ID |
| string | Yes | Source token address |
| string | Yes | Destination token address |
| string | Yes | Amount in smallest unit |
| string | Yes | Sender wallet address |
| string | No | Recipient address |
| number | No | Slippage tolerance (0.005 = 0.5%) |
| string | No | Your integrator ID |
| string[] | No | Allowed bridges (or |
| string[] | No | Denied bridges |
| string[] | No | Preferred bridges |
| string[] | No | Allowed exchanges (or |
| string[] | No | Denied exchanges |
| string[] | No | Preferred exchanges |
| boolean | No | Allow contract calls on destination (default: true) |
| string | No | Route preference: |
| number | No | Integrator fee (0.02 = 2%, max <100%) |
| string | No | Referrer tracking information |
| string | No | Amount to convert to gas on destination |
| number | No | Max price impact threshold (0.1 = 10%, default: 10%) |
| boolean | No | Skip TX simulation for faster response |
| string[] | No | Timing strategy for swap rates |
| string[] | No | Timing 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 with all data needed to execute the swap. See references/REFERENCE.md for complete response schema.
transactionRequest获取包含可直接执行交易数据的单步报价。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 数字 | 是 | 源链ID |
| 数字 | 是 | 目标链ID |
| 字符串 | 是 | 源代币地址 |
| 字符串 | 是 | 目标代币地址 |
| 字符串 | 是 | 最小单位的代币数量 |
| 字符串 | 是 | 发送方钱包地址 |
| 字符串 | 否 | 接收方地址 |
| 数字 | 否 | 滑点容忍度(0.005 = 0.5%) |
| 字符串 | 否 | 你的集成商ID |
| 字符串数组 | 否 | 允许使用的桥接工具(可选值: |
| 字符串数组 | 否 | 禁止使用的桥接工具 |
| 字符串数组 | 否 | 优先使用的桥接工具 |
| 字符串数组 | 否 | 允许使用的交易所(可选值: |
| 字符串数组 | 否 | 禁止使用的交易所 |
| 字符串数组 | 否 | 优先使用的交易所 |
| 布尔值 | 否 | 是否允许在目标链上调用合约(默认:true) |
| 字符串 | 否 | 路线偏好: |
| 数字 | 否 | 集成商手续费(0.02 = 2%,最大值<100%) |
| 字符串 | 否 | 推荐人追踪信息 |
| 字符串 | 否 | 转换为目标链Gas的代币数量 |
| 数字 | 否 | 最大价格影响阈值(0.1 = 10%,默认:10%) |
| 布尔值 | 否 | 跳过交易模拟以加快响应速度 |
| 字符串数组 | 否 | 兑换汇率的时间策略 |
| 字符串数组 | 否 | 路线选择的时间策略 |
示例请求:
bash
curl "https://li.quest/v1/quote?\
fromChain=1&\
toChain=137&\
fromToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&\
toToken=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174&\
fromAmount=1000000000&\
fromAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&\
slippage=0.005"响应包含,其中包含执行兑换所需的所有数据。完整响应架构请参考references/REFERENCE.md。
transactionRequestPOST /advanced/routes
POST /advanced/routes
Get multiple route options for comparison. Returns routes without transaction data (use to get TX data for a specific step).
/advanced/stepTransactionRequest 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 preference. Each route contains but no - use to get TX data.
orderstepstransactionRequest/advanced/stepTransaction获取多个路线选项用于对比。返回的路线不包含交易数据(需使用获取特定步骤的交易数据)。
/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"
}
}'返回按偏好排序的路线数组。每条路线包含但无 - 需使用获取交易数据。
orderstepstransactionRequest/advanced/stepTransactionPOST /advanced/stepTransaction
POST /advanced/stepTransaction
Populate a step (from ) with transaction data. Use this after selecting a route to get the actual transaction to execute.
/advanced/routesRequest Body: Send the full object from a route.
StepQuery Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| boolean | No | Skip 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 populated.
transactionRequest为(来自的)步骤填充交易数据。选择路线后,使用此接口获取可执行的实际交易。
/advanced/routes请求体: 发送路线中的完整对象。
Step查询参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 布尔值 | 否 | 跳过交易模拟以加快响应速度 |
示例:
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": {...}
}'响应: 返回已填充的Step对象。
transactionRequestGET /status
GET /status
Track transaction status across chains. Can query by sending TX hash, receiving TX hash, or transactionId.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Transaction hash (sending, receiving, or transactionId) |
| number | No | Source chain ID (speeds up request) |
| number | No | Destination chain ID |
| string | No | Bridge tool name |
For same-chain swaps, set and to the same value.
fromChaintoChainExample Request:
bash
curl "https://li.quest/v1/status?txHash=0x123abc..."Response includes: , (txHash, amount, chainId), (txHash, amount, chainId), , , .
transactionIdsendingreceivingstatussubstatuslifiExplorerLinkStatus Values: , , , ,
NOT_FOUNDINVALIDPENDINGDONEFAILEDPoll until status is or . See references/REFERENCE.md for complete substatus values.
DONEFAILED跨链追踪交易状态。可通过发送交易哈希、接收交易哈希或transactionId进行查询。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 是 | 交易哈希(发送方、接收方或transactionId) |
| 数字 | 否 | 源链ID(可加快请求速度) |
| 数字 | 否 | 目标链ID |
| 字符串 | 否 | 桥接工具名称 |
对于同链兑换,将和设置为相同值。
fromChaintoChain示例请求:
bash
curl "https://li.quest/v1/status?txHash=0x123abc..."响应包含: 、(txHash、数量、chainId)、(txHash、数量、chainId)、、、。
transactionIdsendingreceivingstatussubstatuslifiExplorerLink状态值: (未找到)、(无效)、(处理中)、(完成)、(失败)
NOT_FOUNDINVALIDPENDINGDONEFAILED轮询直到状态变为或。完整子状态值请参考references/REFERENCE.md。
DONEFAILEDGET /chains
GET /chains
Get all supported chains.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | Filter by chain types: |
bash
curl "https://li.quest/v1/chains"
curl "https://li.quest/v1/chains?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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | Comma-separated chain IDs or keys (e.g., |
| string | No | Filter by chain types: |
| number | No | Min token price filter (default: 0.0001 USD) |
bash
curl "https://li.quest/v1/tokens?chains=1,137,42161"获取指定链的代币列表。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 否 | 逗号分隔的链ID或标识(例如: |
| 字符串 | 否 | 按链类型过滤: |
| 数字 | 否 | 代币最低价格过滤(默认: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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Chain ID or key (e.g., |
| string | Yes | Token address or symbol (e.g., |
bash
curl "https://li.quest/v1/token?chain=POL&token=DAI"获取特定代币的信息。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 是 | 链ID或标识(例如: |
| 字符串 | 是 | 代币地址或符号(例如: |
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:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | Filter by chain IDs |
bash
curl "https://li.quest/v1/tools"
curl "https://li.quest/v1/tools?chains=1,137"Returns and arrays with , , and . Use these keys in , , , etc.
bridgesexchangeskeynamesupportedChainsallowBridgesdenyBridgesallowExchangesSpecial values: , , ,
allnonedefault[]获取可用的桥接工具和交易所。使用此接口发现用于过滤报价的有效工具标识。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 否 | 按链ID过滤 |
bash
curl "https://li.quest/v1/tools"
curl "https://li.quest/v1/tools?chains=1,137"返回包含和的数组,每个元素包含、和。可将这些标识用于、、等参数中。
bridgesexchangeskeynamesupportedChainsallowBridgesdenyBridgesallowExchanges特殊值: 、、、
allnonedefault[]GET /connections
GET /connections
Get available token pair connections. At least one filter (chain, token, bridge, or exchange) is required.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No | Source chain ID or key |
| string | No | Destination chain ID or key |
| string | No | Source token address or symbol |
| string | No | Destination token address or symbol |
| string | No | Filter by chain types: |
| string[] | No | Allowed bridges |
| string[] | No | Denied bridges |
| string[] | No | Preferred bridges |
| string[] | No | Allowed exchanges |
| string[] | No | Denied exchanges |
| string[] | No | Preferred exchanges |
| boolean | No | Include routes requiring chain switch (default: true) |
| boolean | No | Include routes with destination calls (default: true) |
bash
curl "https://li.quest/v1/connections?\
fromChain=POL&\
fromToken=DAI"获取可用的代币对连接。至少需要一个过滤条件(链、代币、桥接工具或交易所)。
参数:
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 否 | 源链ID或标识 |
| 字符串 | 否 | 目标链ID或标识 |
| 字符串 | 否 | 源代币地址或符号 |
| 字符串 | 否 | 目标代币地址或符号 |
| 字符串 | 否 | 按链类型过滤: |
| 字符串数组 | 否 | 允许使用的桥接工具 |
| 字符串数组 | 否 | 禁止使用的桥接工具 |
| 字符串数组 | 否 | 优先使用的桥接工具 |
| 字符串数组 | 否 | 允许使用的交易所 |
| 字符串数组 | 否 | 禁止使用的交易所 |
| 字符串数组 | 否 | 优先使用的交易所 |
| 布尔值 | 否 | 是否包含需要切换链的路线(默认:true) |
| 布尔值 | 否 | 是否包含目标链有合约调用的路线(默认: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']}")
undefinedquote = 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']}")
undefinedNode.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 Status | Description |
|---|---|
| 200 | Success |
| 400 | Bad request - check parameters |
| 429 | Rate limit exceeded - wait or use API key |
| 500 | Internal error - retry |
See references/REFERENCE.md for complete error codes and response schemas.
| HTTP状态码 | 描述 |
|---|---|
| 200 | 请求成功 |
| 400 | 请求参数错误 - 检查参数 |
| 429 | 请求速率超限 - 等待或使用API密钥 |
| 500 | 服务器内部错误 - 重试 |
完整错误码和响应架构请参考references/REFERENCE.md。
Best Practices
最佳实践
-
Always specify slippage - Default is conservative. Adjust based on token volatility.
-
Poll status endpoint - For cross-chain transfers, poll every 5-10 seconds untilor
DONE.FAILED -
Handle rate limits - Implement exponential backoff for 429 responses.
-
Cache chain/token data -and
/chainsresponses change infrequently./tokens -
Use integrator parameter - Always includefor analytics and potential monetization.
integrator -
Validate addresses - Ensure token addresses match the specified chain.
-
Handle gas estimation - The API provides gas estimates, but actual costs may vary.
See references/REFERENCE.md for complete endpoint documentation and response schemas.
-
始终指定滑点 - 默认滑点设置较为保守,可根据代币波动性调整。
-
轮询状态接口 - 对于跨链转账,每5-10秒轮询一次,直到状态变为或
DONE。FAILED -
处理速率限制 - 针对429响应实现指数退避策略。
-
缓存链/代币数据 -和
/chains的响应更新频率较低。/tokens -
使用integrator参数 - 始终包含参数,以便进行数据分析和潜在的变现。
integrator -
验证地址 - 确保代币地址与指定链匹配。
-
处理Gas预估 - API提供Gas预估,但实际成本可能有所不同。
完整接口文档和响应架构请参考references/REFERENCE.md。