Skip to main content

Wallet Flow

  1. List supported tokens.
  2. Quote the swap.
  3. Check quote expiry.
  4. Check Permit2 allowance.
  5. If needed, send an ERC-20 approval transaction and wait for it.
  6. Ask the user to sign the returned EIP-712 typed data.
  7. Submit the order with a clientOrderId.
  8. Poll status until the order is filled, failed, or expired.
BaiBai currently supports gasless EIP-712 orders only. Traditional/non-gasless orders are coming soon.

Constants

Error Handling Helper

All REST errors use this shape:
Use HTTP status codes for retry behavior. 429 responses include retry-after.

List Tokens

Use /tokens to discover supported ERC-20 tokens and decimals.

Quote

Amounts are token base units as decimal strings.
For exact-output swaps, use kind: "buy" and buyAmountAfterFee.

Routing Preference

The optional routingPreference field controls how BaiBai chooses liquidity: Use auto unless your wallet intentionally wants to bias execution.

Check Quote Expiry

Check expiry before signing. If approval, wrapping, or user confirmation takes time, request a fresh quote.

Approve Permit2

Approve quote.permit2.allowanceTarget, not quote.permit2.spender.
allowanceTarget is the Permit2 contract that receives the ERC-20 approval. spender is the BaiBai settlement spender included in the signed typed data.

Sign

Sign quote.permit2.typedData exactly as returned.

Submit

Use clientOrderId to make submit retries idempotent.
If the network fails after submit, retry the same request with the same clientOrderId. BaiBai returns the existing order instead of creating a duplicate.

Poll

Poll every 1-2 seconds, then back off to every 5 seconds for longer-running orders.

Native ETH

Native ETH is not a gasless order token. Use WETH in quote and order requests.
  • Swapping from ETH: request an indicative quote with WETH as the sell token, then wrap ETH to WETH before signing/submitting.
  • Swapping to ETH: quote and buy WETH, then unwrap WETH after fill.
  • The wallet/caller owns the wrap and unwrap transactions.
Base WETH: 0x4200000000000000000000000000000000000006

Swapping from ETH

Quote with WETH before the user wraps:
Then wrap, approve Permit2, check quote expiry, sign, and submit:

Swapping to ETH

Quote WETH as the buy token, submit the order, then unwrap after it fills:

Retry Guidance

Aggregator Flow

Quote, sign, submit, status, routing, and retry concepts.

API Reference

Endpoint fields, examples, errors, rate limits, and OpenAPI.

BaiBai Overview

Product overview and architecture.