跳转到主要内容
POST
/
trade
/
swap
Execute trade via aggregator (EVM + Solana)
curl --request POST \
  --url https://api.afkcrypto.com/v1/trade/swap \
  --header 'Content-Type: application/json' \
  --header 'Idempotency-Key: <idempotency-key>' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "chain": "<string>",
  "fromToken": "<string>",
  "toToken": "<string>",
  "amount": "<string>",
  "from": "<string>",
  "slippage": 1,
  "includeGas": true,
  "protocols": "<string>",
  "excludeProtocols": "<string>"
}
'
{ "id": "tx_...", "status": "SUBMITTED", "hash": "0x...", "explorerUrl": "https://solscan.io/tx/...", "chainName": "Solana" }
使用 NATIVE 关键字于 fromToken/toToken 来交换原生资产(ETH、SOL 等)。需要 Idempotency-Key 头。仅 Solana 主网。对于 EVM,如兑换因 allowance 错误失败,请先批准代币。
{ "id": "tx_...", "status": "SUBMITTED", "hash": "0x...", "explorerUrl": "https://solscan.io/tx/...", "chainName": "Solana" }

授权

x-api-key
string
header
必填

请求头

Idempotency-Key
string<uuid>
必填

Provide a unique Idempotency-Key per user to ensure single submission.

请求体

application/json
chain
string
必填

EVM chain slug.

fromToken
string
必填

Token or native address (0xEeee... for native)

toToken
string
必填

Output token address (0x...).

amount
string
必填

Amount in wei (decimal or 0x-hex supported for EVM).

from
string | null

Optional sender wallet; defaults to user's default wallet for the chain.

slippage
number
默认值:1

Percentage (e.g., 1 = 1%). Optional; defaults to 1%.

includeGas
boolean | null

Include gas estimates in the build (optional).

protocols
string | null

Comma-separated allowlist of protocols (optional).

excludeProtocols
string | null

Comma-separated blocklist of protocols (optional).

响应

Submission accepted

id
string
必填

AFK transaction id for the submitted action.

status
enum<string>
必填

Submission status.

可用选项:
SUBMITTED
hash
string | null
必填

On-chain transaction hash/signature (may be null at submission time).

explorerUrl
string | null
必填

Direct link to the transaction on a chain explorer. Null until a hash/signature exists.

chainName
string
必填

Human-readable chain name for display (e.g., Base, Ethereum, Solana).