swap

Build an unsigned swap transaction. Routes to user for signing.

Tier: Free

Parameters

ParameterTypeRequiredDescription
sellTokenstringYesToken to sell — symbol (e.g. “USDC”) or contract address
buyTokenstringYesToken to buy — symbol or contract address
sellAmountstringYesAmount to sell in human-readable units (e.g. “100” for 100 USDC)
chainIdnumberNoChain ID (default: 1)
slippagenumberNoSlippage tolerance in % (default: 1)

The sender’s wallet address is resolved automatically from the Y0_API_KEY session — no need to pass it explicitly.

Example

"Swap 100 USDC to ETH on Ethereum"

Signing Flow

  1. MCP server calls signing service /api/build/swap
  2. Signing service fetches route from 0x (fallback: 1inch)
  3. Unsigned tx is queued with status pending
  4. User gets WebSocket notification
  5. User reviews and signs on their device
  6. Returns pending transaction ID

Notes

  • Non-custodial: y0 never touches the signed transaction
  • Uses 0x as primary router, 1inch as fallback
  • Transaction expires after 5 minutes if not signed