One line of code to accept digital dollars. HTTP-native x402 payment protocol for blockchain payments with Express middleware and Axios client support.
X402-Payment-System is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on blockchain-payments, bnb, ethereum, evm. It currently has 1 GitHub stars and 0 forks, and sits alongside related tools like x402-sandbox, x402-sandbox, payflow.
A simple, HTTP-native protocol for on-chain payments. x402 makes it trivial for web services to accept low-fee, fast blockchain payments with minimal integration.
"One line of server code to accept digital dollars — no fee, ~2s settlement, $0.001 minimum payment."
Quick example (Express):
import { paymentMiddleware } from 'x402-payment-system';
app.use(
paymentMiddleware({
payTo: "0xYourAddress",
prices: { "/your-endpoint": "$0.01" },
networkId: "56" // BNB Chain
})
);
See examples/typescript/servers/express.ts for a complete example.
Requirements
Install and run examples (from the repository root):
# from repo root
cd examples/typescript
pnpm install; pnpm build
cd examples/typescript
copy .env.example .env
# Edit .env and set:
# - PAY_TO: Your payment receiving address
# - PRIVATE_KEY: Client's private key for signing payments
# - RPC_URL: BNB Chain RPC endpoint (optional)
cd examples/typescript
pnpm dev:server
# Or: pnpm server
cd examples/typescript
pnpm dev:client
# Or: pnpm client
You should see the client successfully request and receive the resource after paying.
x402 was designed to solve shortcomings of existing online payment systems (high fees, friction, and poor programmatic control). Key principles:
x402 reuses HTTP status 402 (Payment Required). Typical flow:
X-PAYMENT: <base64(json)>./verify)./settle.X-PAYMENT-RESPONSE header (base64 JSON) describing settlement details.This design allows resource servers to trade off immediate response vs stronger settlement guarantees.
Payment Required Response (server -> client)
{
"x402Version": 1,
"accepts": [ /* paymentRequirements */ ],
"error": "" // optional
}
paymentRequirements
{
"scheme": "string", // logical payment scheme (eg. "exact")
"network": "string", // chain/network id
"maxAmountRequired": "string",// maximum amount in atomic units
"resource": "string", // resource URL
"description": "string",
"mimeType": "string",
"outputSchema": null | {},
"payTo": "string", // recipient address
"maxTimeoutSeconds": 30,
"asset": "string", // e.g. ERC20 contract address where appropriate
"extra": null | {} // scheme-specific metadata
}
Payment Payload (sent by client in X-PAYMENT, base64-encoded JSON)
{
"x402Version": 1,
"scheme": "exact",
"network": "1",
"payload": { /* scheme-specific */ }
}
A facilitator is an optional 3rd-party that performs verification and on-chain settlement so resource servers don't need node or wallet access.
POST /verify
Request body
{
"x402Version": 1,
"paymentHeader": "<base64-payment-header>",
"paymentRequirements": { /* object from server */ }
}
Response
{
"isValid": true,
"invalidReason": null
}
POST /settle
Request body same as /verify.
Response
{
"success": true,
"error": null,
"txHash": "0x...",
"networkId": "1"
}
GET /supported
Response
{
"kinds": [ { "scheme": "exact", "network": "1" } ]
}
Schemes are logical payment methods (for example exact, which transfers a fixed amount). Each (scheme, network) pair defines how the payload is built, verified, and settled. Implementations and facilitators must declare supported pairs.
The repo contains a first-pass spec for exact on EVM chains at specs/schemes/exact/scheme_exact_evm.md.
examples/typescript/servers/express.ts — Express resource server using x402 middleware.examples/typescript/clients/axios — Example client that follows the 402 flow and pays via X-PAYMENT header.Follow the Getting started section above to run them locally.
x402-payment-system/
├── src/ # Core library source
│ ├── types.ts # TypeScript type definitions
│ ├── utils.ts # Utility functions (encoding/decoding)
│ ├── middleware/ # Express middleware
│ │ └── express.ts
│ ├── client/ # Client implementations
│ │ └── axios.ts
│ ├── schemes/ # Payment scheme implementations
│ │ └── exact/
│ │ └── evm.ts
│ └── __tests__/ # Unit tests
├── examples/ # Example implementations
│ └── typescript/
│ ├── servers/ # Server examples
│ └── clients/ # Client examples
├── specs/ # Protocol specifications
│ └── schemes/
└── dist/ # Compiled output
From the repository root:
# Install dependencies
pnpm install
# Run tests
pnpm test
This runs the unit tests for the x402 library.
Contributions are welcome. Please follow these guidelines:
CONTRIBUTING.md (if present). If not present, open an issue to discuss large changes first.specs/schemes.pnpm test.See ROADMAP.md (if present) for longer-term plans and priorities.
This project is provided under the terms of the LICENSE file in the repository root.
One-command local development environment for HTTP 402 Payment Required protocol with blockchain payments (EIP-3009 USDC)
💻 Spin up a complete local x402 payment server to test the HTTP 402 Payment Required protocol with blockchain payments effortlessly.
A toolkit for building micropayment-gated MCP servers
Open Source AI trading agent that operates autonomously across 1000+ markets - Polymarket, Kalshi, Binance, Hyperliquid, Solana DEXs, 5 EVM chains. Scans for edge, executes instantly, manages risk while you sleep. Agent commerce protocol for machine-to-machine payments. Self-hosted. Built on Claude.
Drop-in OpenAI Python client with transparent x402 payment support.
Drop-in OpenAI Typescript client with transparent x402 payment support.
TypeScript Interface for Machine Payments Protocol
Production-ready x402 facilitator server.
Rust SDK for the x402 payment protocol.