
x402 Rust Implementation
A high-performance, type-safe Rust implementation of the x402 HTTP-native micropayment protocol.
Features โข Quick Start โข Examples โข Documentation
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
โจ Features
- ๐ HTTP-native micropayments: Leverage the HTTP 402 status code for payment requirements
- โ๏ธ Blockchain integration: Support for EIP-3009 token transfers with real wallet integration
- ๐ Web framework support: Middleware for Axum, Actix Web, and Warp
- ๐ฐ Facilitator integration: Built-in support for payment verification and settlement
- ๐ Type safety: Strongly typed Rust implementation with comprehensive error handling
- ๐งช Comprehensive testing: 62+ tests with 100% pass rate covering all real implementations
- ๐๏ธ Real implementations: Production-ready wallet, blockchain, and facilitator clients
๐ Quick Start
Creating a Payment Server with Axum
use ;
use ;
use Arc;
async
async
๐ณ Making Payments with a Client
use X402Client;
use ;
async
๐๏ธ Architecture
The Rust implementation is organized into several modules:
- ๐ฆ
types: Core data structures and type definitions - ๐
client: HTTP client with x402 payment support - ๐ฐ
facilitator: Payment verification and settlement - ๐ง
middleware: Web framework middleware implementations - ๐
crypto: Cryptographic utilities for payment signing - โ
error: Comprehensive error handling - ๐ฆ
wallet: Real wallet integration with EIP-712 signing - โ๏ธ
blockchain: Blockchain client for network interactions - ๐ญ
real_facilitator: Production-ready facilitator implementation
๐ Supported Web Frameworks
- ๐ Axum: Modern, ergonomic web framework
- โก Actix Web: High-performance actor-based framework
- ๐ชถ Warp: Lightweight, composable web server
โ๏ธ Blockchain Support
Currently supports:
- ๐๏ธ Base: Base mainnet and testnet
- โ๏ธ Avalanche: Avalanche mainnet and Fuji testnet
- ๐ EIP-3009: Transfer with Authorization standard
๐ Examples
See the examples/ directory for complete working examples:
- ๐
axum_server.rs: Payment server using Axum - ๐ณ
client.rs: Client making payments - ๐ฐ
facilitator.rs: Custom facilitator implementation - ๐ฆ
real_implementation_demo.rs: Real wallet and blockchain integration - ๐
real_wallet_integration.rs: Production-ready wallet integration
๐ Testing
- โ 62+ tests with 100% pass rate
- ๐งช Comprehensive coverage of all real implementations
- ๐ Integration tests for end-to-end workflows
- ๐ก๏ธ Error handling tests for robust error scenarios
๐ License
Licensed under the Apache License, Version 2.0. See LICENSE for details.