Protocol Integrations

x402 HTTP Payment Protocol

x402 repurposes HTTP's dormant 402 Payment Required status code for machine-to-machine payments. An agent hits an endpoint, gets told what it costs, pays, gets the resource. All automated — invisible to the developer.

What x402 Actually Is

The HTTP 402 status code has existed since 1991, reserved for "Payment Required" but never formally implemented. x402 activates it as a machine-to-machine payment standard: a resource server emits a 402 response with structured payment details, the client constructs and signs a payment payload, retries the request, and the facilitator verifies and settles on-chain.

The key developer-facing insight: agent.fetch() handles all of this transparently. From a developer's perspective it looks identical to a normal fetch call — the entire payment layer is invisible. REAPP intercepts the flow at step 3 to inject mandate validation before any signing happens.

The Full Payment Flow on Stellar

REAPP-Augmented x402 Flow on Stellar
Full request-to-settlement flow. REAPP adds mandate validation before any signing happens. The resource server sees a standard x402 flow — REAPP's additions are invisible to it.

Developer Transparency

The entire 7-step flow is abstracted behind a single function call. This is the core DX principle — agents should be able to pay for resources with the same ergonomics as fetching them.

agent.fetch() — Single Line Payment
// This is ALL the developer writes:
const data = await agent.fetch('https://api.dataservice.com/premium/report');

// agent.fetch() internally handles:
// 1. Initial request → receives 402
// 2. AP2 mandate validation against payment details
// 3. Soroban spending limit check
// 4. XDR transaction construction + agent signing
// 5. Facilitator verification
// 6. Retry with X-PAYMENT header
// 7. Stellar settlement (~3 seconds)
// 8. Audit trail recording on-chain
// 9. Returns response data

Why Stellar Beats EVM for Agentic Payments

Stellar's native advantages over EVM x402 directly enable the micropayment economics required for agentic commerce. The numbers matter at scale: an agent making 100 API calls per day at $0.001 each spends $0.10 — the same workflow on Ethereum at $0.01 minimum costs $1.00, ten times more.

FeatureEVM x402Stellar x402
Settlement time~12 seconds2–5 seconds
Minimum payment~$0.01 (gas overhead)$0.001
Mainnet feeVariable gas$0.00001 fixed
Fee sponsorshipMeta-transactions (EIP-2771)Fee-bump (native primitive)
Transaction formatEIP-712 typed dataXDR native
Expiry mechanismTimestamp (validBefore)Ledger sequence (precise)
Native stablecoinERC-20 contract requiredUSDC via SAC (native)
Replay protectionNonce-based (stateful)Sequence numbers (protocol-level)

Official @x402/* v2 Package Architecture

REAPP builds on the official @x402/* v2 package ecosystem from Coinbase, documented under the stellar/x402-stellar GitHub org and at developers.stellar.org/docs/build/apps/x402. The v2 architecture is transport-agnostic and chain-agnostic — REAPP registers a Stellar-specific scheme that plugs into this ecosystem.

PackagePurpose
@x402/coreTransport-agnostic client, server, facilitator components
@x402/expressExpress middleware for payment-gated routes
@x402/fetchAuto-paying fetch wrapper
@x402/axiosAxios interceptor variant
@x402/nextNext.js integration
@x402/paywallModular paywall UI
@x402/extensionsExtension support
@x402/* v2 → @reapp/sdk Dependency Graph
REAPP wraps official @x402/* packages with mandate-awareness. The composition is additive — @x402/* handles settlement, REAPP adds authorization, enforcement, and audit trail.

Stellar-Specific Mechanics

The Stellar x402 implementation differs from EVM/SVM in key ways that directly benefit agentic micropayments:

  • Soroban auth-entry signing — clients sign InvokeHostFunctionOp with expiration constraints (max_ledger bounds + random nonce for replay protection)
  • Fee bump sponsorship — the facilitator sponsors network fees via fee bump transactions, so clients need zero XLM
  • SEP-41 token standard — supports both built-in Stellar assets and Soroban contract assets
  • Compatible wallets: Freighter, Albedo, Hana, HOT, Klever, OneKey (Freighter Mobile does NOT support x402 yet)

Core Protocol Types

Core Protocol Types (@x402/core)
// From @x402/core — defines the entire protocol surface
type Network = `${string}:${string}`;  // CAIP-2: "stellar:pubnet", "stellar:testnet"

type PaymentRequirements = {
  scheme: string;
  network: Network;
  asset: string;
  amount: string;
  payTo: string;
  maxTimeoutSeconds: number;
  extra: Record<string, unknown>;
};

type PaymentPayload = {
  x402Version: number;
  resource: ResourceInfo;
  accepted: PaymentRequirements;
  payload: Record<string, unknown>;
  extensions?: Record<string, unknown>;
};

Server Registration Pattern

Server Registration with x402 Middleware (proposed API)
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
import { HTTPFacilitatorClient } from "@x402/core/server";
import { ExactStellarScheme } from "@reapp/x402-stellar/exact/server";

const facilitatorClient = new HTTPFacilitatorClient({
  url: "https://channels.openzeppelin.com/x402/testnet",
});
const server = new x402ResourceServer(facilitatorClient)
  .register("stellar:testnet", new ExactStellarScheme());

app.use(paymentMiddleware(
  { "GET /api/data": {
    accepts: [{ scheme: "exact", price: "$0.001",
      network: "stellar:testnet", payTo: "GBXE2KP4FXQF3JKDMR5H6CDHGLPRCAQNBOV3YF7OAHQB6GZXDP7WMKE" }],
    description: "Paid API endpoint"
  }},
  server,
));
Testnet MVP — example pricing

The prices shown in code examples ($0.001, $0.10, $1.00) and the comparison table minimums ($0.001 Stellar vs ~$0.01 EVM) are illustrative. Actual pricing for production endpoints will be set by individual fulfillment agents and may vary based on market dynamics.

Facilitator Trust Model

The facilitator is a non-custodial service that verifies payment signatures and submits transactions to the blockchain. REAPP treats it as part of the threat surface — the SDK is facilitator-agnostic. The OpenZeppelin Relayer x402 Plugin implements the full facilitator API and is the recommended production path:

  • Testnet: https://channels.openzeppelin.com/x402/testnet
  • Mainnet: https://channels.openzeppelin.com/x402
  • Source: github.com/OpenZeppelin/relayer-plugin-x402-facilitator

Fee sponsorship uses the OpenZeppelin Relayer Channels — the replacement for LaunchTube, which was archived on March 9, 2026. The OZ Relayer sponsors network fees via fee bump transactions, so agent clients need zero XLM to operate. If the relayer is unavailable, agents pay standard Stellar fees ($0.00001 per operation).