# Qiguard API

The Qiguard API prices token swaps and builds the transaction for them on BSC, Ethereum, Base and Polygon. Every trade settles in one transaction through the Qiguard router of the chain, straight from the taker's wallet.


You can add your own fee to every trade with `swapFeeRecipient` and `swapFeeBps` (up to 3 wallets, 300 bps in total); it is paid to you on chain in the same transaction. Not in v1: exact-out (`buyAmount`) and the `/swap/permit2/*` endpoints.

## Products

| Product | What it does | Chains |
|---|---|---|
| Swap (allowance holder) | `price` and `quote`; the quote returns the transaction the taker sends | BSC, Ethereum, Base, Polygon |
| Gasless | The taker signs a Permit2 message; the Qiguard relayer sends the transaction and pays the gas | BSC, Base |

| Chain | chainId | Swap | Gasless | Sources | Listed tokens |
|---|---|---|---|---|---|
| BSC | 56 | yes | yes | `PancakeSwap_V2`, `PancakeSwap_V3` | 46 |
| Ethereum | 1 | yes | no | `Uniswap_V2`, `Uniswap_V3` | 54 |
| Base | 8453 | yes | yes | `Uniswap_V2`, `Uniswap_V3` | 21 |
| Polygon | 137 | yes | no | `QuickSwap_V2`, `Uniswap_V3` | 16 |

Gasless is being enabled per chain; until then `POST /gasless/submit` returns `503 GASLESS_NOT_ENABLED`, and `GET /gasless/chains` shows `enabled: false` for that chain. Gasless price and quote work on both chains meanwhile.

## Base URL and headers

- Base URL: `https://api.qiguard.com`. HTTPS only.
- Keyed endpoints (price, quote and gasless) need two headers: `qg-api-key: qg_sk_...` and `qg-version: v1`.
- Keyless endpoints: `GET /swap/chains`, `GET /gasless/chains`, `GET /sources`, `GET /tokens`, `GET /status`.
- Amounts are decimal strings in base units. Responses use checksummed addresses. The native coin of every chain is `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`.
- Every response carries the header `qg-zid` and the body field `zid`. Keep it in your logs: it identifies the request.

## Access

1. Sign in at [dashboard.qiguard.com](https://dashboard.qiguard.com) with MetaMask.
2. Create an app (products and chains) and a secret key.
3. Every new app is reviewed during the invite phase. Until it is approved, its keys answer `403 APP_NOT_APPROVED`.

The [Quickstart](quickstart.md) walks through the first price, quote and swap.

## What the API does not do

- It never holds user funds or user keys. The taker's wallet approves the settlement contract (or Permit2 for gasless) and the contract pays the output to the taker in the same transaction.
- Swaps are exact-in: `sellAmount` is fixed, `buyAmount` is computed.
- One route per trade: one liquidity source family per chain (a V2 and a V3 source), at most two hops.

## Pages

- [Swap](swap.md): parameters, pairs, fees, approvals and the transaction.
- [Gasless](gasless.md): Permit2 signature, submit, status and sponsored gas.
- [API reference](reference.md): every endpoint, parameter, response and schema.
- [Errors](errors.md), [Rate limits and plans](rate-limits.md), [Idempotency](idempotency.md), [Versioning](versioning.md).
- [Contracts and fees](contracts.md), [Security](security.md), [Testing](testing.md), [Changelog](changelog.md).
- Machine-readable: [openapi.yaml](openapi.yaml), [openapi.json](openapi.json), [llms.txt](llms.txt).
