> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rach.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Swap

> Same-chain and cross-chain token swaps with quotes and slippage protection.

The Swap API converts one token into another — same-chain (e.g. USDC → USDT on Polygon,
via Rach's on-chain FiatSwapV2 proxy) or cross-chain (e.g. Polygon → BSC, via a bridge).
Quote first, then execute. Authenticate with your Payments API key (`X-API-Key`).

<Info>
  Base URL: `https://api.rach.finance/api/v1/` · Auth: `X-API-Key` (quote is public)
</Info>

## 1. Get a quote

`GET /swap/quote` is public — no key required.

```bash theme={null}
curl "https://api.rach.finance/api/v1/swap/quote?from_chain=POL&to_chain=POL&from_token=USDC&to_token=USDT&amount_in=100"
```

```json Response theme={null}
{
  "from_chain": "POL",
  "to_chain": "POL",
  "from_token": "USDC",
  "to_token": "USDT",
  "from_amount": "100",
  "to_amount_expected": "99.85",
  "to_amount_min": "99.35",
  "platform_fee": "0.30",
  "estimated_seconds": 30,
  "expires_at": 1755168000
}
```

`to_amount_min` reflects slippage protection — the swap reverts if output would fall below
it.

## 2. Execute the swap

Run the swap for a customer wallet. Pass `amount_out_min` (use the quote's `to_amount_min`)
to protect against slippage.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.rach.finance/api/v1/swap/customer/cust_001 \
    -H "X-API-Key: $RACH_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "from_chain": "POL",
      "to_chain": "POL",
      "from_token": "USDC",
      "to_token": "USDT",
      "amount_in": "100",
      "amount_out_min": "99.35"
    }'
  ```

  ```js Node theme={null}
  const swap = await (await fetch("https://api.rach.finance/api/v1/swap/customer/cust_001", {
    method: "POST",
    headers: { "X-API-Key": process.env.RACH_KEY, "Content-Type": "application/json" },
    body: JSON.stringify({
      from_chain: "POL", to_chain: "POL",
      from_token: "USDC", to_token: "USDT",
      amount_in: "100", amount_out_min: "99.35",
    }),
  })).json();
  ```
</CodeGroup>

```json Response theme={null}
{ "tx_hash": "0x9f8e...", "status": "pending" }
```

## 3. Track history

```bash theme={null}
curl https://api.rach.finance/api/v1/swap/customer/cust_001/history \
  -H "X-API-Key: $RACH_KEY"
```

<Note>
  Same-chain swaps on Polygon and BSC route through Rach's FiatSwapV2 proxy (0.30% platform
  fee, applied on-chain). Cross-chain swaps bridge via an aggregator and take longer —
  `estimated_seconds` reflects the route.
</Note>

See the **Swap** endpoints in the [Payments API Reference](/api-reference/introduction).
