Skip to main content
Add token swaps to your app with the 0x Swap API. 0x searches liquidity across decentralized exchanges and market makers, then returns a transaction that the user’s wallet can simulate, sign, and submit on Base.

Demo

The demo above is mock only. If you want to see onchain demos on Vibenet, head to Base chain demos.

Route a Swap with 0x

Use the AllowanceHolder flow for a B20 or ERC-20 swap:
  1. Request an indicative /price while the user edits the trade.
  2. Request a firm /quote when the user is ready to review and sign.
  3. If issues.allowance is present, approve only the returned spender for the sell amount.
  4. Fetch a fresh quote, simulate its transaction, submit it, and wait for confirmation.
Never approve the 0x Settler contract. Approve only the AllowanceHolder or Permit2 address returned by the API in issues.allowance.spender or allowanceTarget.
Install viem@2.55.19, create Base publicClient and walletClient instances in clients.ts, and keep ZERO_EX_API_KEY on your server. This example sells 100 USDC for WETH on Base mainnet.
The verified sample uses a server-side wallet only to keep the example runnable. In a user-facing app, request the quote from your backend, return the reviewed transaction fields to the frontend, and submit them with the user’s connected wallet.
This snippet is illustrative. It shows the shape of a routed trading integration on Base, not production-ready code. Follow the 0x Swap API documentation for current API behavior, supported liquidity sources, fees, and contract details.
trade-0x.ts

0x Documentation

Swap API Quickstart

Follow the full price, allowance, quote, and submission flow.

AllowanceHolder Quote

Review every request parameter and response field.

Token Allowances

Approve the correct spender and avoid unsafe approvals.

See Also

Integrate Lending

Let users supply USDC to a money market.

Integrate Borrowing

Open a collateralized loan against WETH.

Integrate an Earn Product

Route deposits into yield-bearing vaults.