Skip to content

Architecture

Overview

x402 RPC Proxy is designed as a modular, multi-layered system that separates authentication, payments, routing, and execution.

It acts as an intermediary layer between clients and blockchain nodes, enforcing access control, payment validation, and request metering before forwarding requests.


High-Level Architecture

The system consists of four primary layers:

┌─────────────────────────────────────────────┐
│              Client Layer                   │
│  Apps · Backends · AI Agents · Wallets      │
└─────────────────────┬───────────────────────┘
                      │ JSON-RPC 2.0 / REST
┌─────────────────────▼───────────────────────┐
│            Gateway Layer (x402)             │
│  Auth · Credit Check · Routing · Metering   │
└──────┬────────────────────────┬─────────────┘
       │                        │
┌──────▼──────┐        ┌────────▼────────────┐
│  Payment &  │        │   RPC Provider      │
│  Credit     │        │   Layer             │
│  Layer      │        │   EVM · Cosmos ·    │
│             │        │   Solana (planned)  │
└─────────────┘        └─────────────────────┘

Request Lifecycle

Every RPC request follows a deterministic flow:

  1. Client sends request to /mcp
  2. Gateway authenticates the request (JWT)
  3. Credits are checked
  4. If insufficient → return 402 Payment Required
  5. If sufficient → deduct credits
  6. Route request to appropriate RPC provider
  7. Return response to client

This ensures strict enforcement of payment before execution.


Core Components

API Gateway

The gateway is the central entry point:

  • Exposes a single endpoint: /mcp
  • Implements JSON-RPC 2.0
  • Handles request validation and routing
  • Acts as the enforcement layer for auth and credits

Authentication Layer

Responsible for identity and session management:

FeatureDetail
Supported standardsSIWE (Ethereum), SIWC (Cosmos), SIWS (Solana — upcoming)
Token typeJWT (short-lived access + refresh token pair)
Session stateRefresh tokens, expiry tracking, revocation support

Payment & Credit Layer

Handles economic enforcement:

StepAction
1Pricing plans defined by the platform
2Consumer makes on-chain payment
3Gateway verifies payment on-chain
4Credits issued to consumer wallet
5Credits deducted atomically before each request

Routing Layer

Responsible for selecting RPC endpoints:

  • Supports multiple providers per chain
  • Handles load distribution, failover, and endpoint selection
  • Abstracts underlying RPC infrastructure from the client

Execution Layer

Handles actual RPC forwarding:

ProtocolTransport
JSON-RPCStandard EVM and Cosmos RPC
RESTCosmos LCD / REST APIs
gRPCHigh-performance binary
WebSocketStreaming and subscriptions

Data Flows

Authentication Flow

Client                    Gateway
  │                          │
  │── GET /auth/nonce ───────▶│
  │◀─ { nonce } ─────────────│
  │                          │
  │  [sign message in wallet]│
  │                          │
  │── POST /auth/login ──────▶│
  │   { address, sig, msg }  │── verify signature
  │                          │── issue JWT
  │◀─ { token, refresh } ────│

Payment Flow

Client                    Gateway                  Chain
  │                          │                       │
  │── GET /pricing ──────────▶│                       │
  │◀─ { plans } ─────────────│                       │
  │                          │                       │
  │── POST /payments/initiate▶│                       │
  │◀─ { recipient, amount } ─│                       │
  │                          │                       │
  │── [on-chain transfer] ───────────────────────────▶│
  │                          │                       │
  │── POST /payments/confirm ▶│── verify tx ─────────▶│
  │                          │◀─ confirmed ──────────│
  │◀─ { credits_issued } ────│                       │

Execution Flow

Client                    Gateway              Provider
  │                          │                    │
  │── POST /mcp ─────────────▶│                    │
  │   { jsonrpc, method }    │── check JWT         │
  │                          │── check credits     │
  │                          │── deduct credits    │
  │                          │── route request ───▶│
  │                          │◀─ rpc response ─────│
  │◀─ { jsonrpc, result } ───│                    │

Multi-Chain Support

x402 is designed to support multiple ecosystems:

EcosystemAuthStatus
EVM-based chainsSIWEAvailable
Cosmos-based chainsSIWCAvailable
SolanaSIWSPlanned

Each chain can have:

  • Multiple providers
  • Independent pricing models
  • Different transport protocols

Scalability Considerations

The system is designed for horizontal scalability:

ComponentScaling Strategy
GatewayStateless — scale horizontally
Payment ProcessorIndependent service, scalable separately
RPC ProvidersMultiple providers per chain; auto-routing
Session StoreDistributed token validation

Reliability & Failover

MechanismDescription
Multi-provider routingMultiple RPC endpoints registered per chain
Automatic failoverReroutes on provider failure
Retry policiesConfigurable per-provider retry behavior
Health monitoringProvider health checks (planned)

Security Model

LayerMechanism
IdentityWallet signature — no passwords or shared secrets
SessionShort-lived JWT; single-use refresh tokens
AuthorizationRequest-level credit check before execution
Payment integrityOn-chain verification — not self-reported
Abuse preventionCredit exhaustion causes hard stop

Design Principles

PrincipleDescription
Separation of concernsAuth, payments, routing, and execution are independent layers
Deterministic executionPayment enforced before request — no exceptions
ExtensibilityNew chains and payment networks can be integrated
InteroperabilityUnified interface across all supported ecosystems
Minimal trustVerifiable payments and auditable usage at every step

Built on open standards — JSON-RPC 2.0, HTTP 402, SIWx.