मुख्य सामग्री पर जाएं
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" }
नेटिव एसेट्स (ETH, SOL, आदि) की अदला-बदली के लिए fromToken/toToken में NATIVE कीवर्ड का उपयोग करें। 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).