A comprehensive Rust toolkit for the x402 protocol, enabling blockchain payments directly through HTTP using the native
402 Payment Requiredstatus code.
x402-rs is a modular, production-ready implementation of the x402 protocol with support for multiple blockchains (EVM, Solana, Aptos, ..) and protocol versions (V1 and V2).
| Crate | Badges | Description |
|---|---|---|
x402-types |
Core protocol types, facilitator traits, and utilities. Foundation for all x402 implementations. | |
x402-axum |
Axum middleware for protecting routes with x402 payments. | |
x402-reqwest |
Reqwest middleware for transparent x402 payment handling. | |
x402-facilitator-local |
Local facilitator implementation for payment verification and settlement. |
| Crate | Badges | Description |
|---|---|---|
x402-chain-eip155 |
EVM/EIP-155 chain support (Ethereum, Base, Polygon, etc.) | |
x402-chain-solana |
Solana blockchain support | |
x402-chain-aptos |
Aptos blockchain support (requires git dependency) |
| Crate | Description |
|---|---|
x402-facilitator |
Production-ready facilitator server binary (not published to crates.io) |
The x402 protocol is a proposed standard for making blockchain payments directly through HTTP using the native 402 Payment Required status code.
How it works:
- Server declares payment requirements for specific routes
- Client sends cryptographically signed payment payloads
- Facilitator verifies and settles payments on-chain
This enables seamless pay-per-use transactions without requiring clients to manage blockchain interactions directly.
Use x402-axum to gate your routes behind on-chain payments:
use alloy_primitives::address;
use axum::{Router, routing::get};
use x402_axum::X402Middleware;
use x402_chain_eip155::V2Eip155Exact;
use x402_types::networks::USDC;
let x402 = X402Middleware::new("http://facilitator.example.com");
let app = Router::new().route(
"/paid-content",
get(handler).layer(
x402.with_price_tag(V2Eip155Exact::price_tag(
address!("0xYourAddress"),
USDC::base_sepolia().amount(10u64),
))
),
);See x402-axum documentation for more details.
Use x402-reqwest to automatically handle x402 payments:
use x402_reqwest::{ReqwestWithPayments, ReqwestWithPaymentsBuild, X402Client};
use x402_chain_eip155::V2Eip155ExactClient;
use alloy_signer_local::PrivateKeySigner;
use std::sync::Arc;
use reqwest::Client;
let signer: Arc<PrivateKeySigner> = Arc::new("0x...".parse()?);
let x402_client = X402Client::new()
.register(V2Eip155ExactClient::new(signer));
let client = Client::new()
.with_payments(x402_client)
.build();
let res = client
.get("https://example.com/protected")
.send()
.await?;See x402-reqwest documentation for more details.
Prebuilt Docker images are available at GitHub Container Registry:
docker run -v $(pwd)/config.json:/app/config.json -p 8080:8080 ghcr.io/x402-rs/x402-facilitatorFor custom facilitator implementations, see the Build Your Own Facilitator guide.
For full facilitator configuration and deployment details, see the x402-facilitator README.
| Milestone | Description | Status |
|---|---|---|
| Facilitator for Base USDC | Payment verification and settlement service, enabling real-time pay-per-use transactions for Base chain. | ✅ Complete |
| Metrics and Tracing | Expose OpenTelemetry metrics and structured tracing for observability, monitoring, and debugging | ✅ Complete |
| Server Middleware | Provide ready-to-use integration for Rust web frameworks such as axum and tower. | ✅ Complete |
| Client Library | Provide a lightweight Rust library for initiating and managing x402 payment flows from Rust clients. | ✅ Complete |
| Solana Support | Support Solana chain. | ✅ Complete |
| Protocol v2 Support | Support x402 protocol version 2 with improved payload structure. | ✅ Complete |
| Multiple chains and multiple tokens | Support various tokens and EVM compatible chains. | ✅ Complete |
| Axum Middleware v2 Support | Full x402 protocol v2 support in x402-axum with multi-chain, multi-scheme architecture. | ✅ Complete |
| Reqwest Client v2 Support | Full x402 protocol v2 support in x402-reqwest with multi-chain, multi-scheme architecture. | ✅ Complete |
| Build your own facilitator hooks | Pre/post hooks for analytics, access control, and auditability. | 🔜 Planned |
| Bazaar Extension | Marketplace integration for discovering and purchasing x402-protected resources. | 🔜 Planned |
| Gasless Approval Flow | Support for Permit2 and ERC20 approvals to enable gasless payment authorization. | 🔜 Planned |
| Upto Scheme | Payment scheme supporting "up to" amount payments with flexible pricing. | 🔜 Planned |
| Deferred Scheme | Payment scheme supporting deferred settlement and payment scheduling. | 🔜 Planned |
Feel free to open issues or pull requests to improve x402 support in the Rust ecosystem.