Skip to main content
The SDK includes working examples in the x402r-sdk/ repository. Each is a standalone project that demonstrates a specific integration pattern.

Examples

facilitator

Operator-agnostic HTTP service implementing x402’s facilitator protocol for escrow payments. Handles signature verification and on-chain settlement.

deploy-operator

Deploy a complete marketplace operator with escrow, freeze, and arbiter support.

server-express

Express merchant server using EscrowServerScheme, HTTPFacilitatorClient, and refundable() to accept escrow payments via x402 middleware.

server-hono

Hono merchant server using EscrowServerScheme, HTTPFacilitatorClient, and refundable() to accept escrow payments via x402 middleware.

merchant-cli

CLI tool for merchants to release payments, approve/deny refunds, and query escrow state.

client-cli

CLI tool for payers to pay, preview-fee, request refunds, freeze payments, and check status.

arbiter-cli

CLI tool for arbiters to review cases, make decisions, and manage registry.

shared

Shared utilities used by the CLI examples: parsePaymentInfo, shortAddress, formatUSDC.

Running Examples

All examples require a private key with Base Sepolia ETH and USDC. See Base network faucets for testnet tokens.
The full payment flow requires the facilitator to be running before the merchant server:
# All commands run from the x402r-sdk/ root directory

# 1. Set up environment files
cp examples/facilitator/basic/.env-local examples/facilitator/basic/.env
# Edit .env — set PRIVATE_KEY

cp examples/servers/express/.env-local examples/servers/express/.env
# Edit .env — set ADDRESS, OPERATOR_ADDRESS, FACILITATOR_URL

# 2. Start the facilitator (port 4022)
pnpm example:facilitator

# 3. Start the merchant server (new terminal, port 4021)
pnpm example:server:express
# Or: pnpm example:server:hono

# 4. Make a payment (new terminal)
pnpm example:client-cli pay --url http://localhost:4021/weather
The facilitator must be running before the merchant server (Express or Hono) starts, as the merchant delegates payment verification and settlement to it.

deploy-operator

Deploys a complete marketplace operator using deployMarketplaceOperator():
import { deployMarketplaceOperator } from '@x402r/core/deploy';

const result = await deployMarketplaceOperator(
  walletClient,
  publicClient,
  'eip155:84532',
  {
    feeRecipient: account.address,
    arbiter: arbiterAddress,
    escrowPeriodSeconds: 604800n, // 7 days
    operatorFeeBps: 100n,         // 1%
  }
);
See Deploy an Operator for the full guide.

Server Examples

Demonstrates minimal merchant servers (Express and Hono variants) that use EscrowServerScheme, HTTPFacilitatorClient, and refundable() via x402’s standard middleware:
  1. Returns 402 with refundable() payment options
  2. Delegates payment verification to the facilitator via HTTPFacilitatorClient
  3. Delegates on-chain settlement to the facilitator after the handler runs
  4. Returns weather data after successful payment

Next Steps

Deploy Operator

Deploy a PaymentOperator with escrow and freeze support.

refundable() Helper

Mark payment options as refundable with escrow configuration.

Core Concepts

Understand the payment lifecycle and key concepts.

GitHub

Browse all examples on GitHub.