Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)

说明与用途

x402 通过标准 HTTP 头和 ERC‑4337 UserOperation,使 AI 代理能够支付 API 调用费用,保持无状态并简化集成。

问题

AI agents need to call paid services without manual billing layers, yet traditional payment flows break stateless HTTP contracts.

结果

Implemented a minimal x402 server protecting an /echo endpoint and a client that pays via ERC‑20 on Base, demonstrating stateless HTTP‑native micropayments for AI agents.

工作流

  • Send normal GET/POST to resource URL
  • Receive 402 Payment Required with Pay‑Payload header
  • Extract payment request, sign with wallet to create ERC‑4337 UserOperation
  • Base64‑encode UserOperation and add X‑Payment header
  • Retry original request with X‑Payment header
  • Server verifies payment proof, credits payer, returns 200 OK with resource

证据

The client extracts the payment request, signs it with its wallet, and resends the request with an X‑Payment header containing the signed proof.

来源

Because the payment proof lives in an HTTP header, any HTTP client (fetch, axios, curl, language‑specific HTTP libraries) can participate without changing the endpoint URL or adding a SDK‑specific wrapper.

来源

  • 记录日期: 2026-09-14T18:01:01.024Z