openfacilitator

x402 payment integration via OpenFacilitator SDK. Use when implementing crypto payments, paywalls, API monetization, or tipping/transfer flows. Triggers: "x402", "OpenFacilitator", "crypto payments", "USDC payments", "paywall", "payment middleware", "verify and settle", "402 Payment Required". Supports EVM (Base, Ethereum, Polygon, Arbitrum, Avalanche, Sei, IoTeX, Peaq, X Layer) and Solana and Stacks chains.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "openfacilitator" with this command: npx skills add rawgroundbeef/openfacilitator/rawgroundbeef-openfacilitator-openfacilitator

OpenFacilitator x402 SDK

Add x402 crypto payments to any TypeScript/JavaScript server. The SDK handles payment verification, on-chain settlement, and optional refund protection.

Install

npm install @openfacilitator/sdk

Both ESM and CJS are supported. Package version: 1.0.0.

Core Concept

x402 is an HTTP-native payment protocol. A server returns 402 Payment Required with payment requirements. The client signs a payment and retries with an X-PAYMENT header. The server verifies and settles the payment on-chain.

The OpenFacilitator SDK provides two integration patterns:

  1. Middleware (recommended) — Drop-in Express or Hono middleware that handles the full 402 flow automatically.
  2. Manual verify + settle — Call verify() and settle() yourself for full control over business logic between verification and settlement.

Quick Start — Middleware

Express

import { createPaymentMiddleware } from '@openfacilitator/sdk';
import type { PaymentContext } from '@openfacilitator/sdk';

const paymentMiddleware = createPaymentMiddleware({
  facilitator: 'https://pay.openfacilitator.io',
  getRequirements: () => ({
    scheme: 'exact',
    network: 'base',
    maxAmountRequired: '1000000', // $1 USDC (6 decimals)
    asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
    payTo: '0xYOUR_WALLET_ADDRESS',
  }),
});

app.post('/api/resource', paymentMiddleware, (req, res) => {
  // Payment verified & settled. Access context:
  const { transactionHash, userWallet, amount } =
    (req as unknown as { paymentContext: PaymentContext }).paymentContext;
  res.json({ success: true, txHash: transactionHash });
});

Hono

import { honoPaymentMiddleware } from '@openfacilitator/sdk';
import type { PaymentContext } from '@openfacilitator/sdk';

// Declare paymentContext variable for type-safe c.get()
type Env = { Variables: { paymentContext: PaymentContext } };
const app = new Hono<Env>();

app.post('/api/resource', honoPaymentMiddleware({
  facilitator: 'https://pay.openfacilitator.io',
  getRequirements: (c) => ({
    scheme: 'exact',
    network: 'base',
    maxAmountRequired: '1000000',
    asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
    payTo: '0xYOUR_WALLET_ADDRESS',
  }),
}), async (c) => {
  const ctx = c.get('paymentContext');
  return c.json({ success: true, txHash: ctx.transactionHash });
});

Quick Start — Manual Verify + Settle

import { OpenFacilitator } from '@openfacilitator/sdk';

const facilitator = new OpenFacilitator(); // defaults to pay.openfacilitator.io

const requirements = {
  scheme: 'exact',
  network: 'base',
  maxAmountRequired: '1000000',
  asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
  payTo: '0xYOUR_WALLET_ADDRESS',
};

// 1. Verify the payment
const verifyResult = await facilitator.verify(paymentPayload, requirements);
if (!verifyResult.isValid) {
  throw new Error(verifyResult.invalidReason);
}

// 2. Your business logic here (create order, check inventory, etc.)

// 3. Settle on-chain (async — waits for confirmation)
const settleResult = await facilitator.settle(paymentPayload, requirements);
if (!settleResult.success) {
  throw new Error(settleResult.errorReason);
}
// settleResult.transaction = on-chain tx hash

Pattern Selection Guide

Use CasePatternSee
Simple API paywallMiddlewarereferences/patterns.md §1-2
Business logic between verify and settleManual verify + settlereferences/patterns.md §3
Per-request dynamic pricingMiddleware with dynamic getRequirementsreferences/patterns.md §4
Refund protectionEither pattern + refund configreferences/patterns.md §5
Accept multiple chainsEither pattern + array requirementsreferences/patterns.md §6
Build EVM payment payload (ERC-3009)Client constructionreferences/client-construction.md §1
Build Solana payment payloadClient constructionreferences/client-construction.md §2
Server-side signing (Openfort/Privy/Turnkey)Custodial patternreferences/client-construction.md §3
Solana gas-free with fee payerFee payer integrationreferences/client-construction.md §2

Key Facts

  • Amounts are always in smallest units: 1000000 = $1 USDC (6 decimals).
  • Network IDs: Use v1 short names (base, solana, stacks) in requirements. The SDK handles CAIP-2 conversion internally.
  • settle() is synchronous-feeling but async — it waits for on-chain confirmation before returning the tx hash. No webhooks needed for settlement confirmation.
  • Payment header: Clients send X-PAYMENT header containing base64-encoded JSON.
  • Default facilitator: https://pay.openfacilitator.io (free, no account needed).
  • Refund protection is opt-in via middleware config. Requires an API key from the dashboard.

Common USDC Addresses

ChainAsset AddressDecimals
Base0x833589fCD6eDb6E08f4c7C32D4f71b54bdA029136
Ethereum0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB486
SolanaEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v6

See references/schemas.md for the full chain and token table.

References

  • references/sdk-api.md — Full TypeScript signatures, all exports, error classes
  • references/schemas.md — Payment objects, requirements, chain/token details
  • references/patterns.md — Complete working examples for every server-side integration pattern
  • references/client-construction.md — How to BUILD payment payloads (ERC-3009, Solana SPL, fee payer, server-side signing)
  • references/troubleshooting.md — Error handling, retries, edge cases

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

x402lint

No summary provided by upstream source.

Repository SourceNeeds Review
General

x402storage

No summary provided by upstream source.

Repository SourceNeeds Review
General

x402check

No summary provided by upstream source.

Repository SourceNeeds Review
General

x402-ecosystem

No summary provided by upstream source.

Repository SourceNeeds Review