402 Payment Required into a payment handshake. Your service advertises price and settlement requirements, the agent signs a USDC authorization, and the facilitator verifies and settles it without accounts or API keys.
Demo
These samples use TypeScript@x402/*@2.21.0, Go x402/go/v2@v2.21.0, Python x402==2.18.0, and Base Sepolia (eip155:84532). The test facilitator is https://x402.org/facilitator.
Before a live test, query the facilitator’s
/supported endpoint and confirm eth_getCode returns bytecode for the advertised asset and settlement contracts. Base Sepolia state and test assets can be reset independently of an SDK release.1
Return the payment requirements
Without a payment signature, middleware returns 402 with the supported scheme, CAIP-2 network, asset, amount, and receiver.
2
Verify the signed retry
The client selects a supported requirement, applies its local spend policy, signs, and retries with
PAYMENT-SIGNATURE.3
Run the protected handler
Middleware verifies the payload before invoking your code.
upto and batch-settlement can set the actual charge on the successful response.4
Settle through the facilitator
Exact and upto settle per request. Batch settlement stores the latest voucher and periodically claims, settles, or refunds channels.
Accept a fixed-price payment
Charge a known amount before returning the resource.Settle a usage-based payment
Advertise a maximum, then settle the actual usage after the handler succeeds.Batch high-frequency payments
Verify cumulative vouchers per request and claim them through a durable channel manager.The complete batch fixtures configure a dedicated
RECEIVER_AUTHORIZER_PRIVATE_KEY to sign claim and refund authorizations. Keep it separate from the receiving wallet and store it in a server-side key manager.Call a paid x402 service
Register every scheme you permit, then reject unexpected networks or spend before the wallet signs. The wrapper handles the 402 retry; your code still validates the paid response as untrusted input.TypeScript buyer