Expand description
§r402
x402 Payment Protocol SDK for Rust — umbrella crate.
This crate re-exports the workspace under feature flags. Prefer depending on individual crates when you need a minimal dependency graph.
§Included crates
| Feature | Crate | Role |
|---|---|---|
| (always) | r402-core | Wire types, Facilitator, schemes, hooks, extensions |
evm (default) | r402-evm | EVM exact + upto (ERC-3009 / Permit2) |
svm | r402-svm | Solana exact (SPL Token / Token-2022) |
tron | r402-tron | Tron exact (TIP-712 / EIP-3009 + Permit2) |
casper | r402-casper | Casper exact (CEP-18, remote facilitator) |
http (default) | r402-http | Axum middleware + reqwest client |
mcp | r402-mcp | MCP transport on official rmcp (V2) |
Forwarding features: client, server, facilitator, telemetry, cache,
ext-bazaar, ext-payment-id, all-extensions, full.
§Quick Start
[dependencies]
# Minimal EVM HTTP server/client
r402 = { version = "0.15", features = ["evm", "http", "client", "server", "facilitator"] }
# Multi-chain
r402 = { version = "0.15", features = [
"evm", "svm", "tron", "casper",
"http", "client", "server", "facilitator",
] }ⓘ
// After enabling the matching features:
use r402::evm; // r402-evm
use r402::svm; // r402-svm
use r402::tron; // r402-tron
use r402::casper; // r402-casper
use r402::http; // r402-http
use r402::mcp; // r402-mcp (needs feature "mcp")§Features
| Flag | Default | What it enables |
|---|---|---|
evm | yes | Re-export r402-evm as evm |
svm | Re-export r402-svm as svm | |
tron | Re-export r402-tron as tron | |
casper | Re-export r402-casper as casper | |
http | yes | Re-export r402-http as http |
mcp | Re-export r402-mcp as mcp | |
client | Forward client to enabled chain + http crates | |
server | Forward server to enabled chain + http crates | |
facilitator | Forward facilitator (Casper also enables http-client) | |
telemetry | Forward telemetry / tracing | |
cache | r402-core settlement cache | |
ext-bazaar | Bazaar extension | |
ext-payment-id | Payment-identifier extension | |
all-extensions | All built-in extensions | |
full | Every feature above |
§License
Licensed under either of MIT or Apache-2.0, at your option.
Re-exports§
pub use r402_casper as casper;casperpub use r402_evm as evm;evmpub use r402_http as http;httppub use r402_mcp as mcp;mcppub use r402_svm as svm;svmpub use r402_tron as tron;tron
Modules§
- amount
- Human-readable currency amount parsing.
- cache
cache - Shared cache primitives used by facilitator implementations.
- chain
- Blockchain-specific types and providers for x402 payment processing.
- error
- Layered error types for x402 facilitator operations.
- error_
reason - Machine-readable error codes used in x402 verify/settle responses.
- extensions
- Extension framework for x402 protocol extensions.
- facilitator
- Unified asynchronous interface for x402 payment facilitators.
- hooks
- Lifecycle hooks for facilitator verify / settle operations.
- payment
- Typestate lifecycle for a single x402 payment.
- resource_
server - Resource-server orchestration shared by HTTP and MCP transports.
- scheme
- Scheme identifiers, registry, and the extensible payment scheme system.
- wire
- On-the-wire JSON types for the x402 protocol.
Structs§
- Hook
Settle Context - Context passed to settle-related hooks.
- Hook
Verify Context - Context passed to verify-related hooks.
- Hooked
Facilitator - Facilitator decorator that runs registered hooks around verify and settle.
- Payment
Problem - A structured payment-problem record returned through wire boundaries.
- Resource
Server - Server-side payment orchestrator (Go
X402ResourceServersubset).
Enums§
- Client
Error - Client-side error returned when constructing / signing payments.
- Error
Reason - Canonical error code returned on the wire when a payment fails.
- Facilitator
Error - Top-level facilitator failure.
- Failure
Recovery - Outcome returned by “on failure” hooks, indicating whether recovery happened.
- Hook
Decision - Decision returned by “before” hooks to control whether the operation proceeds.
- Settlement
Error - Settlement-phase failures.
- Verification
Error - Verification-phase failures.
Traits§
- AsPayment
Problem - Trait for converting errors into
PaymentProblems. - DynFacilitator
- Object-safe erasure of
Facilitator, suitable for storing asBox<dyn DynFacilitator>orArc<dyn DynFacilitator>. - DynFacilitator
Hooks - Object-safe erasure of
FacilitatorHooks. - Facilitator
- Unified asynchronous interface for x402 facilitators.
- Facilitator
Hooks - Lifecycle hooks for facilitator verify and settle operations.
Type Aliases§
- BoxFuture
- Boxed future alias used by
DynFacilitatorand legacy code. - Wire
Payment Payload - Wire payment payload with typed requirements and opaque scheme body.