Wallet Flow
- List supported tokens.
- Quote the swap.
- Check quote expiry.
- Check Permit2 allowance.
- If needed, send an ERC-20 approval transaction and wait for it.
- Ask the user to sign the returned EIP-712 typed data.
- Submit the order with a
clientOrderId. - Poll status until the order is
filled,failed, orexpired.
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: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.kind: "buy" and buyAmountAfterFee.
Routing Preference
The optionalroutingPreference 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
Approvequote.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
Signquote.permit2.typedData exactly as returned.
Submit
UseclientOrderId to make submit retries idempotent.
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.
0x4200000000000000000000000000000000000006
Swapping from ETH
Quote with WETH before the user wraps:Swapping to ETH
Quote WETH as the buy token, submit the order, then unwrap after it fills:Retry Guidance
Related Docs
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.