Test x402 payments
The x402 test script walks through the complete payment flow from the agent’s perspective: request without payment, receive 402, decode the challenge, sign an ERC-3009 authorization, and resubmit with the signature.
PAYMENT_STUB_MODE
During development, set PAYMENT_STUB_MODE=true on your server. In stub mode, the server accepts any payment credential without verifying it on-chain. This lets you test the full HTTP flow without a funded wallet or a real blockchain connection.
Set PAYMENT_STUB_MODE=false in production. Stub mode accepts any credential — it bypasses all payment verification.
The test script (example-06)
This is the full x402 agent from example-06-x402-agent.ts. Run it against your server to verify the integration end-to-end:
Run the test
Expected output:
Testing with real funds
To test with real USDC on Base (mainnet):
- Set
PAYMENT_STUB_MODE=false on your server
- Fund the agent wallet with USDC on Base
- Run the same script — the
signX402Payment function works identically; the difference is the server submits the authorization to Base mainnet