Overview
x402r uses an additive modular fee system:totalFee = protocolFee + operatorFee. Each layer is independently configurable, and the operator splits fees between a shared protocol recipient and a per-operator fee recipient.
Fee Architecture
Two Fee Layers
Example Calculation
For a 1000 USDC payment with 50 bps protocol fee + 250 bps operator fee: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
The operator locks fees at authorization time so later protocol fee changes don’t break already-authorized payments.authorize()calculates fees and stores them inauthorizedFees[hash]capture()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. CalldistributeFees() to disburse them:
- 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_RECEIVER - Reset accumulated tracking to 0
ProtocolFeeConfig
Shared protocol-level fee governance with built-in safety:Constants
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_RECEIVER Roles
The operator’sFEE_RECEIVER varies by use case:
Fee Configuration Comparison
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.
