Swap
Create a swap order (POST /v1/swap)
Creates an order with the chosen provider. No JWT is required. Optional header x-api-key-partner attributes the order to a partner; an invalid key returns 401 INVALID_API_KEY.
NestJS default status for this POST is 201 Created.
engine (must be one of cex | dex | private):
cex— off-chain. Send funds todepositAddress(memo:extraIdDepositwhen present).dex— on-chain.depositAddressis typicallynull; followtxCreateMeta/ provider payload.private— two-rail. No Bearer token is checked. Send funds todepositAddress.quoteIdis passed to the private workflow asrouteId.
Rate snapshot (rateId) — UUID from GET /v1/quote. If sent:
missing/expired snapshot →
400RATE_EXPIRED(TTL 5 minutes)provider / coin UUIDs / amount do not match the snapshot →
400RATE_MISMATCH(error.detailslists expected vs received)
quoteId is the provider quote id (rate lock) and is independent of rateId.
receiveAddress is validated against the destination token regexAddress when the catalog has one (INVALID_RECEIVE_ADDRESS). refundAddress is validated against the source token (INVALID_REFUND_ADDRESS).
addressFrom is accepted for backward compatibility and ignored.
transactionId in the response is the YiFi UUID stored in admin-service (use it on GET /v1/transactions/{id}). externalTransactionId is the provider id when it differs. accessToken is issued once — store it client-side.
Optional partner API key on POST /v1/swap. Invalid key → 401. Omitted → anonymous swap.
Provider slug from the chosen quote's provider field
providerXSource token ticker
ETHSource chain slug — same as GET /v1/chains → id (case-insensitive)
ETHTarget token ticker
USDCTarget chain slug — same as GET /v1/chains → id (case-insensitive)
ETHSwap engine to use. Must match the engine from the selected quote.
-
cex– off-chain CEX swap -
dex– on-chain DEX swap -
private– two-rail private swap (no JWT required on this API)
cexPossible values: Amount to exchange in source token units
1.5Quote ID from /v1/quote. Locks in the rate with providers that support it.
abc123Internal rate ID from /v1/quote response. Use to record the exact quote shown to the user in the transaction history. The snapshot expires 5 minutes after the quote was issued. If you pass an expired or unknown ID the request will be rejected with RATE_EXPIRED.
4f2e6d6b-6e15-4f47-8b6e-2a3d3c5b9d10Destination wallet address for the output token
0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbLegacy field. Accepted (not rejected by validation) but not used by createSwap.
0x1234567890abcdef1234567890abcdef12345678Slippage tolerance in percent. Default "0.5". Applies to DEX routes only (engine=dex). Ignored for CEX and private.
0.5Example: 0.5Memo / tag for the destination address. Required for tokens that need it (e.g. XRP, XLM, TON).
1234567890Address to receive a refund if the swap fails. Recommended when the chosen provider or route requires it — follow provider documentation and support guidance. Strongly recommended for private swaps.
0x1234567890abcdef1234567890abcdef12345678Memo / tag for the refund address, if required by the source network
1234567890Partner affiliate referral code (alias of refCode). Optional: without a code the swap is created as usual. Attributes the swap to the partner via their affiliate referral node.
BSS67FAYPartner affiliate referral code. Attributes the swap to the partner via their affiliate referral node. Optional. If both ref and refCode are sent, ref wins. An unknown code is rejected with REFERRAL_CODE_NOT_FOUND.
BSS67FAYOrder created (YiFi UUID + access token + deposit details)
Source token ticker
ETHSource chain slug as sent in the request
ETHTarget token ticker
USDCTarget chain slug as sent in the request
ETHProvider slug executing this swap
providerXYiFi transaction ID. Use this to poll /v1/transactions/{id} for status updates.
3fa85f64-5717-4562-b3fc-2c963f66afa6Issued once at swap creation. Store securely client-side (used for private flows and client-side transaction operations).
a7f3c2d1e9b8405643543343252432aaProvider-side transaction id when it differs from the YiFi UUID in transactionId.
1ad576f82276a5Initial swap status – always pending at the moment of creation
pendingPossible values: Granular step-by-step status map. All values are false at creation. Keys vary by provider and engine.
{"pending":false,"confirming":false,"processing":false,"completed":false}Expected output amount the recipient will receive
1850.25Order expiration from provider response (JSON path configured as expirationTimePath on create-exchange endpoint)
2025-12-01T12:00:00.000ZLegacy: expected output amount (prefer receiveAmount)
1850.25Expected time to complete the swap
~30sAddress to send source funds to. Present for CEX and private routes. null for DEX routes where funds are pulled via smart contract.
0x1234567890abcdef1234567890abcdef12345678Memo / tag for the destination address, if required
1234567890Address that will receive funds if the swap fails
0x1234567890abcdef1234567890abcdef12345678Memo / tag for the refund address, if required
1234567890Raw transaction metadata returned by the provider at creation (e.g. hash, nonce). May be a JSON string.
{"hash": "0x123...", "nonce": 42}Memo / tag for the deposit address, if required by the source network
1234567890Ticker of the token as returned by the provider's internal createExchange response. May differ from fromToken in multi-hop DEX routes.
USDTValidation error, RATE_EXPIRED, RATE_MISMATCH, INVALID_RECEIVE_ADDRESS, or INVALID_REFUND_ADDRESS
Header x-api-key-partner was sent but the key is invalid (INVALID_API_KEY)
COIN_NOT_FOUND or PROVIDER_NOT_FOUND (CEX/DEX only)
WORKFLOW_TIMEOUT (50s create-swap workflow)
SWAP_ERROR, CREATE_TRANSACTION_FAILED, or missing DEX/private task queue
POST /v1/swap HTTP/1.1
Host: api.yifi.io
x-api-key-partner: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 491
{
"provider": "providerX",
"fromToken": "ETH",
"fromNetwork": "ETH",
"toToken": "USDC",
"toNetwork": "ETH",
"engine": "cex",
"amount": 1.5,
"quoteId": "abc123",
"rateId": "4f2e6d6b-6e15-4f47-8b6e-2a3d3c5b9d10",
"receiveAddress": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"addressFrom": "0x1234567890abcdef1234567890abcdef12345678",
"slippageTolerance": "0.5",
"extraIdTo": "1234567890",
"refundAddress": "0x1234567890abcdef1234567890abcdef12345678",
"refundExtraId": "1234567890",
"ref": "BSS67FAY",
"refCode": "BSS67FAY"
}{
"fromToken": "ETH",
"fromNetwork": "ETH",
"toToken": "USDC",
"toNetwork": "ETH",
"provider": "providerX",
"transactionId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"accessToken": "a7f3c2d1e9b8405643543343252432aa",
"externalTransactionId": "1ad576f82276a5",
"status": "pending",
"statusList": {
"pending": false,
"confirming": false,
"processing": false,
"completed": false
},
"receiveAmount": "1850.25",
"expirationTime": "2025-12-01T12:00:00.000Z",
"estimatedOutput": "1850.25",
"estimatedTime": "~30s",
"depositAddress": "0x1234567890abcdef1234567890abcdef12345678",
"extraIdTo": "1234567890",
"refundAddress": "0x1234567890abcdef1234567890abcdef12345678",
"refundExtraId": "1234567890",
"txCreateMeta": "{\"hash\": \"0x123...\", \"nonce\": 42}",
"extraIdDeposit": "1234567890",
"tokenForTx": "USDT"
}Last updated
Was this helpful?