Skip to main content

Flow

BaiBai uses a gasless order flow:
  1. List supported tokens.
  2. Request a quote.
  3. Check quote expiry.
  4. Make sure the sell token is approved for Permit2.
  5. Ask the user to sign the returned EIP-712 typed data.
  6. Submit the quote ID, signature, and optional clientOrderId.
  7. Poll order status until it is terminal.
Only EIP-712 gasless orders are supported today. Traditional/non-gasless orders are coming soon.

Quote

Request quotes with token base-unit amounts as decimal strings.
For exact-output quotes, use kind: "buy" and buyAmountAfterFee.

Quote Expiry

Every quote has two expiry fields:
  • expiration: ISO timestamp for the quote object.
  • quote.validTo: Permit deadline in Unix seconds.
Before asking the user to sign, verify the quote is still fresh. If wrap, approval, or user confirmation takes time, request a new quote.
Do not submit a stale quote. If POST /orders returns an expired-quote error, request a fresh quote and signature.

Routing Controls

routingPreference is optional: Use auto unless your integration has a reason to bias execution.

Approvals

For ERC-20 sell tokens, the user must approve Permit2 before signing/submitting. Approve quote.permit2.allowanceTarget for at least quote.quote.sellAmount:
Check allowance first:
quote.permit2.allowanceTarget is the Permit2 contract that receives the ERC-20 approval. quote.permit2.spender is the BaiBai settlement spender included in the signed typed data. Do not approve spender directly for Permit2 allowance checks.

Signing

Sign the permit2.typedData object returned by /quote exactly as-is.
The typed data is a Permit2 PermitWitnessTransferFrom signature with this BaiBai witness:

Submit

Submit the quote ID and signature. Include clientOrderId when you need idempotency across retries.
If a request with the same clientOrderId was already accepted for the same owner, BaiBai returns the existing order instead of creating a duplicate.

Polling

Poll GET /orders/{orderId} until the status is terminal. A practical polling cadence is every 1-2 seconds, backing off to every 5 seconds for longer-running orders.

Native ETH

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.
  • BaiBai does not wrap or unwrap for integrators.
Base WETH: 0x4200000000000000000000000000000000000006
Wrap before the user signs and submits the gasless order:
After wrapping, check the quote expiry. Request a fresh quote if the original quote is expired or close to expiry.

Retry Guidance

API Reference

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

Wallet Integration

Wallet-side Permit2, signing, polling, and ETH/WETH examples.

BaiBai Overview

Product overview and architecture.