Skip to main content

x402_chain_eip155/
lib.rs

1//! EIP-155 (EVM) chain support for the x402 payment protocol.
2//!
3//! This crate provides implementations of the x402 payment protocol for EVM-compatible
4//! blockchains using the EIP-155 chain ID standard. It supports both V1 and V2 protocol
5//! versions with the "exact" payment scheme based on ERC-3009 `transferWithAuthorization`.
6//!
7//! # Features
8//!
9//! - **V1 and V2 Protocol Support**: Implements both protocol versions with network name
10//!   (V1) and CAIP-2 chain ID (V2) addressing
11//! - **ERC-3009 Payments**: Gasless token transfers using `transferWithAuthorization`
12//! - **Smart Wallet Support**: EIP-1271 for deployed wallets, EIP-6492 for counterfactual wallets
13//! - **Multiple Signers**: Round-robin signer selection for load distribution
14//! - **Nonce Management**: Automatic nonce tracking with pending transaction awareness
15//!
16//! # Architecture
17//!
18//! The crate is organized into several modules:
19//!
20//! - [`chain`] - Core EVM chain types, providers, and configuration
21//! - [`v1_eip155_exact`] - V1 protocol implementation with network names
22//! - [`v2_eip155_exact`] - V2 protocol implementation with CAIP-2 chain IDs
23//!
24//! # Feature Flags
25//!
26//! - `server` - Server-side price tag generation
27//! - `client` - Client-side payment signing
28//! - `facilitator` - Facilitator-side payment verification and settlement
29//! - `telemetry` - OpenTelemetry tracing support
30//!
31//! # Usage Examples
32//!
33//! ## Server: Creating a Price Tag
34//!
35//! ```ignore
36//! use x402_chain_eip155::{V1Eip155Exact, KnownNetworkEip155};
37//! use x402_types::networks::USDC;
38//!
39//! // Get USDC deployment on Base
40//! let usdc = USDC::base();
41//!
42//! // Create a price tag for 1 USDC
43//! let price_tag = V1Eip155Exact::price_tag(
44//!     "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
45//!     usdc.amount(1_000_000u64),
46//! );
47//! ```
48//!
49//! ## Client: Signing a Payment
50//!
51//! ```ignore
52//! use x402_chain_eip155::V1Eip155ExactClient;
53//! use alloy_signer_local::PrivateKeySigner;
54//!
55//! let signer = PrivateKeySigner::random();
56//! let client = V1Eip155ExactClient::new(signer);
57//!
58//! // Use client to sign payment candidates
59//! let candidates = client.accept(&payment_required);
60//! ```
61//!
62//! ## Facilitator: Verifying and Settling
63//!
64//! ```ignore
65//! use x402_chain_eip155::{V1Eip155Exact, Eip155ChainProvider};
66//! use x402_types::scheme::X402SchemeFacilitatorBuilder;
67//!
68//! let provider = Eip155ChainProvider::from_config(&config).await?;
69//! let facilitator = V1Eip155Exact.build(provider, None)?;
70//!
71//! // Verify payment
72//! let verify_response = facilitator.verify(&verify_request).await?;
73//!
74//! // Settle payment
75//! let settle_response = facilitator.settle(&settle_request).await?;
76//! ```
77
78pub mod chain;
79pub mod v1_eip155_exact;
80pub mod v2_eip155_exact;
81pub mod v2_eip155_upto;
82
83mod networks;
84pub use networks::*;
85
86pub use v1_eip155_exact::V1Eip155Exact;
87pub use v2_eip155_exact::V2Eip155Exact;
88pub use v2_eip155_upto::V2Eip155Upto;
89
90#[cfg(feature = "client")]
91pub use v1_eip155_exact::client::V1Eip155ExactClient;
92#[cfg(feature = "client")]
93pub use v2_eip155_exact::client::V2Eip155ExactClient;
94#[cfg(feature = "client")]
95pub use v2_eip155_upto::client::V2Eip155UptoClient;
96
97pub use chain::types::decimal_u256;