Skip to main content

What you need to do

  1. Obtain recipient address (EIP-7702)
  2. Create PaymentRequirements
  3. Parse client X-Payment, verify and settle
  4. Return the resource or a standard 402 accordingly

Prerequisites

  • Seller recipient address: go to app.x402x.ai to create and obtain (EIP-7702 deployed address)
  • Token:
    • USD1 (BSC): 0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d
  • Install dependencies (server):

Core flow (server)

Create server.ts, core logic:
  • Warm-up detection cache: call server.initialize(tokens) on startup to reduce first-request latency
  • Fast mode: disable auto detection when the payment type is known (autoDetect: false)
  • Reuse fixed prices: cache and reuse requirements for fixed-price endpoints to reduce creation overhead
  • Error layering: parse/verify → return 402; settle → return 500 and log

Common integration patterns

  • Fixed-price API: create and cache requirements at app startup, reuse on requests
  • Dynamic pricing API: compute maxAmountRequired and description from request context

Error handling and responses

  • Parse/verify failed: return standard 402 directly (result.status and result.response)
  • Settlement failed or internal exception: return 500 and log details (including payer/txHash if available)

Server SDK

API and middleware

Facilitator

Verification and settlement

Payment Requirements

Field spec

402 Response Format

Standard 402