# TokenSense x402 Buy Token

> TokenSense x402 Buy Token is a paid API for AI agents from x402.wach.ai, paid per call via x402, $0.5/call, status unknown (last checked 2026-09-19).

Executes a token purchase on Base by swapping USDC for a specified ERC-20 token and transferring it to a recipient wallet, paid via x402 micropayment.

## Facts

- Endpoint: POST https://x402.wach.ai/buyToken
- Price: $0.5/call
- Payment: x402
- Status: unknown
- Last checked: 2026-09-19
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/tokensense-x402-buy-token-b061993d
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_loJIjq2xEo_mctF4A_tUX

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability tokensense-x402-buy-token-b061993d -d '<json body>'
```

Example prompt: Buy me some WETH (contract 0x4200000000000000000000000000000000000006) on Base and send it to my wallet at 0xAbCd1234567890AbCd1234567890AbCd12345678 — use USDC to cover the swap.

## When to prefer this

Use this endpoint when you need to programmatically purchase a specific ERC-20 token on Base chain and deliver it to a target wallet, paying with USDC via the x402 micropayment protocol. It is ideal for AI agents that need to automate token acquisition, fund wallets, or execute DeFi swaps without managing DEX interactions directly. Prefer it over generic DEX APIs when you want a single HTTP call that handles swap routing, approval, and transfer in one step with transparent fee breakdown.

## Known failure modes

- Native Base USDC contract address submitted as buyTokenAddress — rejected by API
- Invalid or malformed EVM wallet address (not matching 0x + 40 hex chars) returns validation error
- Insufficient USDC balance in the x402 payment to cover fee + swap amount
- Token contract does not exist or is not tradeable on Base DEX — swap fails
- Network congestion or Base RPC error causes transaction failure
- x402 payment not fulfilled or incorrect amount — endpoint returns 402 Payment Required

## How this service works

x402-paid TokenSense routes, with parallel MPP routes under /mpp/*.

## Output

Returns a JSON object confirming the swap and transfer on Base, including the swap transaction hash, optional approval transaction hash, transfer transaction hash, the formatted amount of output tokens received, and a breakdown of the x402 payment showing the fee portion, swap portion, and total USDC paid.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "walletAddress": {
   "type": "string",
   "pattern": "^0x[a-fA-F0-9]{40}$",
   "description": "Recipient EVM wallet address that receives the purchased token."
  },
  "buyTokenAddress": {
   "type": "string",
   "pattern": "^0x[a-fA-F0-9]{40}$",
   "description": "Base token contract address to buy. Base native USDC is rejected."
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "chain": "base",
  "route": "/buyToken",
  "success": true,
  "execution": {
   "swapTxHash": "0x...",
   "approvalTxHash": null,
   "transferTxHash": "0x...",
   "tokenOutAmountFormatted": "0.001"
  },
  "walletAddress": "0x0000000000000000000000000000000000000000",
  "buyTokenAddress": "0x4200000000000000000000000000000000000006",
  "x402PaymentAssumption": {
   "feeUsdc": "0.02",
   "swapUsdc": "0.48",
   "totalUsdcPaid": "1.0"
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/tokensense-x402-buy-token-b061993d/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402.wach.ai](https://www.zero.xyz/host/x402.wach.ai/llms.txt)
