What you need to do
- Obtain recipient address (EIP-7702)
- Create PaymentRequirements
- Parse client
X-Payment, verify and settle - Return the resource or a standard 402 accordingly
Prerequisites
- Seller recipient address: go to
app.x402x.aito create and obtain (EIP-7702 deployed address) - Token:
- USD1 (BSC):
0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d
- USD1 (BSC):
- Install dependencies (server):
Core flow (server)
- Generic
- Express middleware
- Hono middleware
Create
server.ts, core logic:View full server code (Generic)
View full server code (Generic)
Recommended practices
- 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
requirementsfor 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
requirementsat app startup, reuse on requests - Dynamic pricing API: compute
maxAmountRequiredanddescriptionfrom request context
Error handling and responses
- Parse/verify failed: return standard 402 directly (
result.statusandresult.response) - Settlement failed or internal exception: return 500 and log details (including
payer/txHashif available)