client only.Expand description
Reqwest middleware for automatic x402 payment handling.
This crate provides a X402Client that can be used as a reqwest middleware
to automatically handle 402 Payment Required responses. When a request receives
a 402 response, the middleware extracts payment requirements, signs a payment,
and retries the request with the payment header.
§Registering Scheme Clients
The X402Client uses a plugin architecture for supporting different payment schemes.
Register scheme clients for each chain/network you want to support:
V2Eip155ExactClient(fromr402-evm) - EIP-155 chains, “exact” payment schemeV2SolanaExactClient(fromr402-svm) - Solana chains, “exact” payment scheme
See X402Client::register for more details on registering scheme clients.
§Payment Selection
When multiple payment options are available, the X402Client uses a PaymentSelector
to choose the best option. By default, it uses FirstMatch which selects the first
matching scheme. You can implement custom selection logic by providing your own selector.
See X402Client::with_selector for custom payment selection.
Re-exports§
pub use hooks::ClientHooks;
Modules§
- hooks
- Lifecycle hooks for the x402 client payment creation pipeline.
Structs§
- Reqwest
With Payments Builder - Builder for creating a reqwest client with x402 middleware.
- X402
Client - The main x402 client that orchestrates scheme clients and selection.
Traits§
- Reqwest
With Payments - Trait for adding x402 payment handling to reqwest clients.
- Reqwest
With Payments Build - Trait for building the final client from a
ReqwestWithPaymentsBuilder.
Functions§
- parse_
payment_ required - Parses a 402 Payment Required response into a
proto::PaymentRequired.