Documentation Index
Fetch the complete documentation index at: https://docs.x402r.org/llms.txt
Use this file to discover all available pages before exploring further.
Overview
x402r uses an additive modular fee system:totalFee = protocolFee + operatorFee. Each layer is independently configurable, and fees are split between a shared protocol recipient and a per-operator fee recipient.
Fee Architecture
Two Fee Layers
| Layer | Configured By | Mutability | Recipient |
|---|---|---|---|
| Protocol Fee | ProtocolFeeConfig (shared) | Swappable calculator with 7-day timelock | protocolFeeRecipient on ProtocolFeeConfig |
| Operator Fee | FEE_CALCULATOR (per-operator) | Immutable — set at deploy time | FEE_RECIPIENT on operator |
Example Calculation
For a 1000 USDC payment with 50 bps protocol fee + 250 bps operator fee:| Component | Rate | Amount | Goes To |
|---|---|---|---|
| Protocol Fee | 50 bps (0.5%) | 5.00 USDC | protocolFeeRecipient |
| Operator Fee | 250 bps (2.5%) | 25.00 USDC | FEE_RECIPIENT |
| Total Fee | 300 bps (3%) | 30.00 USDC | |
| Receiver Gets | 970.00 USDC | Payment receiver |
IFeeCalculator Interface
Both protocol and operator fees use the same interface:StaticFeeCalculator
The simplest implementation — returns a fixed basis points value for every payment:StaticFeeCalculatorFactory for deterministic CREATE2 addresses:
Fee Locking
Fees are locked at authorization time to prevent protocol fee changes from breaking already-authorized payments.authorize()calculates fees and stores them inauthorizedFees[hash]release()uses the stored fees — not the current calculator rates- Protocol fee timelocks can’t break already-authorized payments
charge() calculates fees inline since it authorizes and captures atomically — there’s no gap where fees could change.Fee Bounds Validation
Payers commit to an acceptable fee range viaminFeeBps and maxFeeBps in PaymentInfo. The operator validates at authorize() and charge() time:
Fee Distribution
Fees accumulate in the operator contract and are distributed viadistributeFees():
- Check operator’s token balance
- Protocol share =
accumulatedProtocolFees[token](tracked per-token) - Operator share = remaining balance
- Transfer protocol share to
protocolFeeRecipient - Transfer operator share to
FEE_RECIPIENT - Reset accumulated tracking to 0
ProtocolFeeConfig
Shared protocol-level fee governance with built-in safety:Constants
| Parameter | Value |
|---|---|
MAX_PROTOCOL_FEE_BPS | 500 (5%) |
TIMELOCK_DELAY | 7 days |
Calculator Changes (7-Day Timelock)
Recipient Changes (7-Day Timelock)
Disabling Protocol Fees
Set the protocol fee calculator toaddress(0) to disable protocol fees entirely. The operator will calculate 0 bps for the protocol layer.
FEE_RECIPIENT Roles
The operator’sFEE_RECIPIENT varies by use case:
| Use Case | FEE_RECIPIENT | Description |
|---|---|---|
| Marketplace | Arbiter address | Arbiter earns fees for dispute resolution |
| Subscription | Service provider | Provider earns fees for service delivery |
| DAO Grants | DAO multisig | Fees return to treasury |
| Platform | Platform treasury | Platform monetizes via fees |
| B2B Invoice | Platform address | Platform earns for facilitation |
Fee Configuration Comparison
| Use Case | Total Fee | Protocol | Operator | Receiver on 1000 USDC |
|---|---|---|---|---|
| E-Commerce Marketplace | 300 bps (3%) | 50 bps | 250 bps | 970.00 USDC |
| Task Execution Platform | 1300 bps (13%) | 100 bps | 1200 bps | 870.00 USDC |
| Subscription / SaaS | 500 bps (5%) | 50 bps | 450 bps | 950.00 USDC |
| Managed Escrow | 800 bps (8%) | 0 bps | 800 bps | 920.00 USDC |
| B2B Invoice | 100 bps (1%) | 25 bps | 75 bps | 990.00 USDC |
| Freelance / Gig | 1000 bps (10%) | 100 bps | 900 bps | 900.00 USDC |
Next Steps
PaymentOperator
See how fees integrate with PaymentOperator.
Factories
Deploy operators with fee configuration.
Examples
Complete fee configurations for common use cases.
Architecture
Understand the full payment flow.
