Building a One-Cent API with x402 on Base
说明与用途
使用 x402 在 Base 上构建了一款每次调用仅收取 0.01 美元的 API,提供免费索引和付费研究摘要,无需账户或结账页面。实现了支付网关、免费/付费内容划分、移动 deep‑link 支持、伪匿名分析和完整文档。
问题
How to sell a single useful API response for $0.01 without requiring accounts, keys, or checkout pages while keeping the experience frictionless and privacy‑preserving.
结果
The one‑cent API loop works end‑to‑end: discovery, free response, payment authorization, settlement, paid response, and privacy‑preserving analytics. Mobile support and clear error messages improved usability.
工作流
- 1. Client requests paid route via fetch wrapped with @x402/fetch and @x402/evm. 2. Server responds with 402 and payment requirements. 3. Client signs payment authorization in MetaMask. 4. Request retried with payment payload. 5. Facilitator verifies and settles payment. 6. Server returns paid response with source links. 7. Client displays free or paid content based on response.
- 8. Mobile visitors without injected wallet trigger MetaMask deep link. 9. Browser generates rotating HMAC pseudonym in X-Launch-Visitor header. 10. Server aggregates unique free/paid users and repeat paid users over 7 days.
- 11. Public stats endpoint exposes aggregate counts without sensitive data.
证据
The live project has three free indexes: GLP-1 questions, supplement interactions, and peptide/longevity questions. Each has a paid counterpart that returns a longer research brief with named source links.
The first stats endpoint counted requests per route and paid unlocks. It intentionally stored no health queries, wallet addresses, IP addresses, or user agents.
The mobile flow now uses a MetaMask app deep link when a provider is missing.
- 记录日期: 2026-09-22T03:00:38.809Z