ChainPe Docs
Architecture

Services Architecture

Services Architecture

ChainPe runs two Railway-deployed backend services: the facilitator and the indexer. They have distinct responsibilities and different trust levels.

Facilitator

Repository: services/chainpe-facilitator/ Live: https://chainpe-facilitator-production-000a.up.railway.app

Responsibility

Implements the x402 HTTP facilitator contract: POST /verify and POST /settle. Receives a signed USDC payment authorization from the provider proxy, verifies it, and submits it to the Avalanche USDC contract.

Non-custodial design

The facilitator holds only enough AVAX to pay gas. It never holds user USDC. It can only move USDC that the payer already signed and authorized — if the key leaks, an attacker gains the gas balance but cannot steal any payer funds (the EIP-3009 signature is already spent/expired).

API surface

EndpointMethodDescription
/GETService info and endpoint list
/healthGETLiveness check; returns 503 if gas is critically low
/statusGETDetailed status including live gas balance
/supportedGETReturns supported x402 schemes and networks
/metricsGETPrometheus text-format counters
/verifyPOSTVerify a payment payload (does not submit)
/settlePOSTVerify + settle a payment on-chain

Configuration

Env varRequiredDescription
FACILITATOR_PRIVATE_KEYYesGas-paying key; fund with ≥ 0.1 AVAX
NETWORKNoavalanche (default) or fuji
RPC_URLNoAvalanche RPC override
PORTNoHTTP port (Railway injects this)
ALLOWED_ORIGINSNoComma-separated CORS origins

Rate limiting

60 requests per minute per IP. Returns { error: "rate_limit_exceeded" } on excess.

Gas health check

If the gas key balance drops below 0.05 AVAX, /health returns HTTP 503. Railway's health check will restart or alert. The /metrics endpoint exposes chainpe_gas_balance_avax as a Prometheus gauge.


Indexer

Repository: services/chainpe-indexer/ Hosting: self-hosted; there is no public instance right now. On mainnet, chainpe-cloud runs its own indexer behind the provider dashboard.

Responsibility

Watches ChainPeRegistry and ReputationRegistry events on Avalanche, stores them in Postgres, and serves a REST API for O(1) discovery and reputation queries.

Without the indexer, every cp.discover() call would require reading all paginated contract state directly from an RPC node. The indexer makes discovery fast and filterable.

Data model

Two tables:

  • services — one row per active registered service (upserted on events)
  • feedback — one row per ERC-8004 reputation feedback event

API surface

EndpointMethodDescription
/healthGETService health + last indexed block
/statsGETService and feedback counts
/servicesGETPaginated, filtered, ranked service list
/services/:idGETSingle service by key or developer:name
/services/:id/reputationGETReputation summary for a service

Query parameters for GET /services:

  • query — free-text search over name, description, tags
  • tag — filter by exact tag
  • maxPrice — maximum price per request in USDC
  • offset — pagination offset (default 0)
  • limit — page size (default 100, max 100)

Configuration

Env varRequiredDescription
DATABASE_URLYesPostgres connection string (Neon)
CHAINPE_REGISTRY_ADDRESSYesChainPeRegistry contract address
REPUTATION_REGISTRY_ADDRESSNoERC-8004 ReputationRegistry address
NETWORKNoavalanche (default) or fuji
RPC_URLNoAvalanche RPC override
PORTNoHTTP port

Railway deployment

Both services include a railway.json configuration file. Deploy by connecting the repo to Railway and setting the environment variables listed above. Railway automatically provisions a public domain and health-checks the /health endpoint.

On this page