Skip to content

Token Swap API

Execute on-chain DEX swaps and cross-chain bridges from your customers' WaaS wallets — all through a single, unified API endpoint.

Overview

The Swap API lets you swap any token in a customer's wallet for any other token, including across different blockchains. The routing logic is handled automatically:

  • Same-chain swap — executed on-chain through the FiatSwapV2 smart contract (Polygon or BSC), routed via QuickSwap / PancakeSwap
  • Cross-chain bridge — executed through LiFi, covering 20+ EVM-compatible chains

Your integration sees one API. You call the same endpoints whether you're swapping USDC → MATIC on Polygon or bridging USDT from Polygon to Arbitrum.


How Routing Works

mermaid
flowchart TD
    A["POST /api/v1/swap/:customerID"] --> B{Same chain?}
    B -- "Yes (POL or BSC)" --> C[FiatSwapV2 Contract<br/>QuickSwap / PancakeSwap]
    B -- "No (cross-chain)" --> D[LiFi Bridge<br/>20+ chains]
    C --> E[Tx Hash returned]
    D --> E
PairRouteSettlement time
Token → Token on PolygonFiatSwapV2 → QuickSwap / SushiSwap~30 seconds
Token → Token on BSCFiatSwapV2 → PancakeSwap / SushiSwap~30 seconds
Polygon → BSC (or any other chain)LiFi bridge1–10 minutes
Any EVM chain → Any EVM chainLiFi bridge1–10 minutes

Smart Contracts

Polygon (ChainID 137)

ContractAddress
FiatSwapV2 Proxy0x46C75Ead09F097b7fd191998761711D99E48A72C
QuickSwap Router0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff
SushiSwap Router0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506
WMATIC0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270

BSC (ChainID 56)

ContractAddress
FiatSwapV2 Proxy0xB18db6872DA839122d38A2616f8D4FD56533e130
PancakeSwap Router0x10ED43C718714eb63d5aA57B78B54704E256024E
SushiSwap Router0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506
WBNB0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

Platform Fee

FiatSwapV2 charges a platform fee on every on-chain swap. The fee rate is read directly from the contract (calculatePlatformFee). The quote response shows the exact fee before you execute.

For LiFi bridge swaps, fees are set by the bridge protocols and shown in the platform_fee field of the quote.


Key Concepts

from_token / to_token — ERC-20 contract addresses in checksum format. Pass "native" (or the empty string "") to use the chain's native coin (MATIC on Polygon, BNB on BSC).

amount_in — always in base units (wei / smallest denomination). For 1 USDC (6 decimals) pass "1000000". For 1 MATIC (18 decimals) pass "1000000000000000000".

amount_out_min — slippage protection floor, also in base units. Get this from the quote's to_amount_min field. If omitted, defaults to 1 (no slippage protection — not recommended for production).

status: "pending" — swap execution broadcasts the transaction and returns immediately. The transaction settles on-chain asynchronously. Use the tx_hash to check the final status on the blockchain explorer.


Swap Record Status

StatusMeaning
pendingTransaction broadcast, awaiting on-chain confirmation
confirmedTransaction confirmed on-chain
failedTransaction reverted or bridge failed

API Endpoints

MethodPathAuthDescription
GET/api/v1/swap/quoteAPI KeyGet a price quote before executing
POST/api/v1/swap/:customerIDAPI KeyExecute a swap from a customer wallet
GET/api/v1/swap/:customerID/historyAPI KeyCustomer swap history
GET/api/v1/swap/analytics/overviewJWTMerchant dashboard summary
GET/api/v1/swap/analytics/transactionsJWTAll swaps across all customers
GET/api/v1/swap/analytics/volumeJWTDaily swap volume chart data

Next Steps

Rach Payments API