Skip to content

Swap API Reference

Complete endpoint reference for the Token Swap API.

Base URL

https://api.rach.finance

Authentication

Endpoint groupAuth method
/api/v1/swap/quoteAPI Key (X-API-Key header)
/api/v1/swap/:customerIDAPI Key (X-API-Key header)
/api/v1/swap/:customerID/historyAPI Key (X-API-Key header)
/api/v1/swap/analytics/*JWT Token (Authorization: Bearer)

GET /api/v1/swap/quote

Returns a price quote for a swap. Does not execute anything. Quotes expire in 30 seconds.

Query Parameters

ParameterTypeRequiredDescription
from_chainstringYesSource chain identifier. Same-chain: POL, BSC. Cross-chain: any LiFi-supported chain (e.g. ETH, ARB, OP, AVAX). Aliases: POLYGON/MATICPOL, BNB/BINANCEBSC.
to_chainstringYesDestination chain. Must equal from_chain for DEX swaps.
from_tokenstringYesToken contract address (checksum). Use "native" or "" for the chain's native coin (MATIC / BNB).
to_tokenstringYesToken contract address or "native".
amount_instringYesInput amount in base units (no decimals). Must be a positive integer.

Response

json
{
  "from_chain":         "POL",
  "to_chain":           "POL",
  "from_token":         "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
  "to_token":           "native",
  "from_amount":        "100000000",
  "to_amount_expected": "134521000000000000000",
  "to_amount_min":      "133948495000000000000",
  "platform_fee":       "300000",
  "estimated_seconds":  30,
  "expires_at":         1751673028
}
FieldTypeDescription
from_amountstringInput amount in base units
to_amount_expectedstringExpected output at current price (base units)
to_amount_minstringMinimum output after 0.5% slippage (base units) — use this as amount_out_min
platform_feestringPlatform fee deducted from amount_in (base units)
estimated_secondsnumberExpected settlement time
expires_atintegerUnix timestamp when this quote expires (30 seconds from issue)

Error Responses

StatusBodyCause
400{"error": "from_chain, to_chain, from_token, to_token and amount_in are required"}Missing parameters
400{"error": "amount_in must be a positive integer in base units"}Invalid amount
400{"error": "tokenIn and tokenOut resolve to the same address"}Same token for in/out

POST /api/v1/swap/:customerID

Executes a swap from the specified customer's WaaS wallet. The transaction is broadcast and a tx_hash is returned immediately. On-chain confirmation happens asynchronously.

Path Parameters

ParameterDescription
customerIDThe customer ID used when the wallet was provisioned via WaaS

Request Body

json
{
  "from_chain":     "POL",
  "to_chain":       "POL",
  "from_token":     "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
  "to_token":       "native",
  "amount_in":      "100000000",
  "amount_out_min": "133948495000000000000"
}
FieldTypeRequiredDescription
from_chainstringYesSource chain
to_chainstringYesDestination chain
from_tokenstringYesToken address or "native"
to_tokenstringYesToken address or "native"
amount_instringYesAmount in base units
amount_out_minstringNoSlippage floor in base units. Strongly recommended — use quote's to_amount_min. Defaults to 1 if omitted.

Response

json
{
  "tx_hash": "0x4a3f2e1b8c9d7e6f5a4b3c2d1e0f9a8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3",
  "status": "pending"
}
FieldDescription
tx_hashOn-chain transaction hash to track settlement
statusAlways "pending" on successful submission

Error Responses

StatusBodyCause
400{"error": "…"}Invalid request body
401{"error": "business not found in context"}Invalid or missing API key
500{"error": "customer wallet not found for …"}Customer has no provisioned wallet
500{"error": "approve failed: …"}ERC-20 approval failed on-chain
500{"error": "swap transaction failed: …"}Swap reverted (insufficient balance, slippage exceeded, etc.)

GET /api/v1/swap/:customerID/history

Returns paginated swap history for a specific customer wallet.

Path Parameters

ParameterDescription
customerIDCustomer ID

Query Parameters

ParameterDefaultDescription
page1Page number (1-based)
limit20Results per page (max 100)

Response

json
{
  "swaps": [
    {
      "id": 42,
      "business_id": 7,
      "customer_wallet_id": 15,
      "customer_id": "cust_abc123",
      "type": "dex",
      "from_chain": "POL",
      "to_chain": "POL",
      "dex": "quickswap",
      "router_address": "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff",
      "token_in": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
      "token_out": "native",
      "amount_in": "100000000",
      "amount_out": "134521000000000000000",
      "platform_fee": "300000",
      "approve_tx_hash": "0xabc123...",
      "swap_tx_hash": "0x4a3f2e...",
      "status": "confirmed",
      "confirmed_at": "2026-07-04T23:55:12Z",
      "created_at": "2026-07-04T23:54:40Z",
      "updated_at": "2026-07-04T23:55:14Z"
    }
  ],
  "total": 8,
  "page": 1,
  "limit": 20
}

SwapRecord Fields

FieldDescription
type"dex" (same-chain FiatSwapV2) or "bridge" (cross-chain LiFi)
from_chainSource chain
to_chainDestination chain (same as from_chain for DEX swaps)
dexRouter used: quickswap, pancakeswap, sushiswap, or bridge name
router_addressOn-chain router or bridge contract address
amount_inInput amount in base units
amount_outOutput amount in base units (set after on-chain confirmation)
platform_feeFee deducted from amount_in in base units
approve_tx_hashERC-20 approval tx hash (present for token→token and token→native swaps)
swap_tx_hashMain swap transaction hash
statuspending / confirmed / failed
confirmed_atISO 8601 timestamp of on-chain confirmation (null while pending)

GET /api/v1/swap/analytics/overview

Returns a summary of all swaps across all customers for the authenticated merchant. Requires JWT authentication.

Query Parameters

ParameterDefaultDescription
days30Lookback window (1–365)

Response

json
{
  "period": "Last 30 days",
  "total_swaps": 142,
  "dex_swaps": 98,
  "bridge_swaps": 44,
  "pending_swaps": 3,
  "confirmed_swaps": 136,
  "failed_swaps": 3,
  "unique_customers": 27,
  "top_from_chains": [
    { "chain": "POL", "count": 98 },
    { "chain": "BSC", "count": 44 }
  ]
}

GET /api/v1/swap/analytics/transactions

Returns a paginated, filterable list of all swaps across all customers. Requires JWT authentication.

Query Parameters

ParameterDefaultDescription
page1Page number
limit20Per page (max 100)
statusFilter by status: pending, confirmed, failed
typeFilter by type: dex, bridge

Response

json
{
  "swaps": [ /* SwapRecord objects */ ],
  "total": 142,
  "page": 1,
  "limit": 20
}

GET /api/v1/swap/analytics/volume

Returns daily swap counts suitable for a bar chart. Requires JWT authentication.

Query Parameters

ParameterDefaultDescription
days30Lookback window (1–365)

Response

json
{
  "period_days": 30,
  "chart": [
    { "date": "2026-06-05", "total_swaps": 8, "dex_swaps": 6, "bridge_swaps": 2 },
    { "date": "2026-06-06", "total_swaps": 12, "dex_swaps": 9, "bridge_swaps": 3 },
    { "date": "2026-06-07", "total_swaps": 5, "dex_swaps": 4, "bridge_swaps": 1 }
  ]
}

Rach Payments API