الانتقال إلى المحتوى الرئيسي
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 mainnet فقط. بالنسبة لـ 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).