Skip to main content

Crate r402

Crate r402 

Source
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

FeatureCrateRole
(always)r402-coreWire types, Facilitator, schemes, hooks, extensions
evm (default)r402-evmEVM exact + upto (ERC-3009 / Permit2)
svmr402-svmSolana exact (SPL Token / Token-2022)
tronr402-tronTron exact (TIP-712 / EIP-3009 + Permit2)
casperr402-casperCasper exact (CEP-18, remote facilitator)
http (default)r402-httpAxum middleware + reqwest client
mcpr402-mcpMCP 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

FlagDefaultWhat it enables
evmyesRe-export r402-evm as evm
svmRe-export r402-svm as svm
tronRe-export r402-tron as tron
casperRe-export r402-casper as casper
httpyesRe-export r402-http as http
mcpRe-export r402-mcp as mcp
clientForward client to enabled chain + http crates
serverForward server to enabled chain + http crates
facilitatorForward facilitator (Casper also enables http-client)
telemetryForward telemetry / tracing
cacher402-core settlement cache
ext-bazaarBazaar extension
ext-payment-idPayment-identifier extension
all-extensionsAll built-in extensions
fullEvery feature above

§License

Licensed under either of MIT or Apache-2.0, at your option.

Re-exports§

pub use r402_casper as casper;casper
pub use r402_evm as evm;evm
pub use r402_http as http;http
pub use r402_mcp as mcp;mcp
pub use r402_svm as svm;svm
pub use r402_tron as tron;tron

Modules§

amount
Human-readable currency amount parsing.
cachecache
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§

HookSettleContext
Context passed to settle-related hooks.
HookVerifyContext
Context passed to verify-related hooks.
HookedFacilitator
Facilitator decorator that runs registered hooks around verify and settle.
PaymentProblem
A structured payment-problem record returned through wire boundaries.
ResourceServer
Server-side payment orchestrator (Go X402ResourceServer subset).

Enums§

ClientError
Client-side error returned when constructing / signing payments.
ErrorReason
Canonical error code returned on the wire when a payment fails.
FacilitatorError
Top-level facilitator failure.
FailureRecovery
Outcome returned by “on failure” hooks, indicating whether recovery happened.
HookDecision
Decision returned by “before” hooks to control whether the operation proceeds.
SettlementError
Settlement-phase failures.
VerificationError
Verification-phase failures.

Traits§

AsPaymentProblem
Trait for converting errors into PaymentProblems.
DynFacilitator
Object-safe erasure of Facilitator, suitable for storing as Box<dyn DynFacilitator> or Arc<dyn DynFacilitator>.
DynFacilitatorHooks
Object-safe erasure of FacilitatorHooks.
Facilitator
Unified asynchronous interface for x402 facilitators.
FacilitatorHooks
Lifecycle hooks for facilitator verify and settle operations.

Type Aliases§

BoxFuture
Boxed future alias used by DynFacilitator and legacy code.
WirePaymentPayload
Wire payment payload with typed requirements and opaque scheme body.