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

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

Описание и применение

Рецепт автоматизации микроплатежей для автономных ИИ‑агентов с использованием спецификации x402, позволяющей автоматически согласовывать и оплачивать услуги через транзакции ERC‑20.

Задача

Autonomous AI agents need to pay for external services (LLM APIs, data feeds, compute) without human intervention.

Результат

The recipe demonstrates how to implement an x402 client in Node.js/TypeScript that automatically negotiates and pays for micro‑services via on‑chain ERC‑20 transfers, eliminating manual payment steps for AI agents.

Рабочий процесс

  • 1. Send initial HTTP request to the service endpoint.
  • 2. If response status is 402, parse JSON body for amount, token, chainId, and nonce.
  • 3. Validate token and chainId against expected values.
  • 4. Sign an ERC‑20 transfer (e.g., USDC on Base) for the specified amount, including the nonce.
  • 5. Send a retry request with X‑Payment and X‑Payment‑Nonce headers containing the transaction hash.
  • 6. Server verifies on‑chain payment and returns 200 with the requested payload.

Доказательства

x402 repurposes 402 as a negotiation signal: client → server → server → client flow

Источник

Minimal x402 Client (Node.js / TypeScript) example code

Источник

  • Дата записи: 2026-09-15T04:46:09.871Z