402 Payment Required with payment details. The client pays and retries — all transparent to your application code.
Prerequisites
@arcenpay/nodeinstalled- An active ArcenPay API key
- For production: a Redis-compatible nonce store for replay protection
Basic setup
Production setup
For production, use a Redis-backed nonce store for reliable replay protection:Use
RedisNonceStore for multi-instance production deployments. For local development, omit the option — the middleware falls back to an in-memory store.Middleware options
Payment flow
- Client sends a request to your protected endpoint.
- Middleware returns
402 Payment Requiredwith payment details in the response body. - Client’s agent SDK processes the payment on-chain.
- Client retries with payment signature headers.
- Middleware verifies the payment and forwards the request to your handler.
- Your handler receives
req.x402.paymentwith the payment details.
Testing x402 locally with ArcenAgent
Set up a test endpoint and use the agent SDK to verify:Next steps
- Agent payments guide — the client side of x402 payments
- Agent SDK overview — full agent SDK reference
- Webhooks — listen for payment events from x402 transactions

