Request Access
The client sends an
AccessRequest specifying a resourceId and planId. The server creates a payment challenge and returns the amount, destination wallet, and chain ID.Pay and Prove
The client pays USDC on Base (on-chain transfer or EIP-3009 authorization). It then submits the transaction hash as proof. The server verifies the transfer on-chain and issues credentials.
Sequence Diagram
Phase 1 — Challenge
The client sends anAccessRequest with a resourceId and planId. The server looks up the matching plan, creates a PENDING challenge record in the challenge store, and returns an X402Challenge containing:
- amount — the USDC amount to pay (in base units)
- destination — the seller’s wallet address
- chainId —
8453(Base mainnet) or84532(Base Sepolia) - challengeId — a unique identifier for this payment session
Phase 2 — Settlement and Grant
Once the client has paid on-chain, it submits aPaymentProof with the txHash and challengeId. The server then:
- Verifies the ERC-20
Transferevent on Base matches the expected amount, destination, and chain. - Transitions the challenge from PENDING to PAID (atomic, prevents double-spend).
- Calls the seller’s
fetchResourceCredentialscallback to issue a credential (JWT, API key, or any token). - Transitions from PAID to DELIVERED and returns an
AccessGrantwith the token and resource URL.
ChallengeEngine, which enforces the state machine invariants and logs every transition for auditability.
Three Transports, One Engine
Every transport shares the sameChallengeEngine instance, so payment logic, state management, and security invariants are identical regardless of how the client connects.
| Transport | Endpoint | Use Case |
|---|---|---|
| REST (x402) | /x402/access | Simple HTTP 402 payment flow |
| A2A JSON-RPC | {basePath}/jsonrpc | Agent-to-agent protocol with x402 middleware |
| A2A Executor | Native A2A via @a2a-js/sdk | Full A2A protocol integration |
Next Steps
Payment Flow Details
Full walkthrough of every state transition and error path.
State Machine
The complete PENDING / PAID / DELIVERED / EXPIRED / REFUNDED state diagram.
Settlement Strategies
Direct transfer vs. EIP-3009 authorization and facilitator settlement.
Two Modes
Embedded SDK vs. standalone Docker service.

