Skip to main content

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:
This enables flexible fee models, static rates, volume-based tiers, per-token pricing, or any custom logic.

StaticFeeCalculator

The simplest implementation, returns a fixed basis points value for every payment:
Deploy via 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.
Flow:
  1. authorize() calculates fees and stores them in authorizedFees[hash]
  2. capture() uses the stored fees, not the current calculator rates
  3. 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 via minFeeBps and maxFeeBps in PaymentInfo. The operator validates at authorize() and charge() time:
This ensures payers always know the fee range they’re agreeing to.

Fee Distribution

Fees accumulate in the operator contract. Call distributeFees() to disburse them:
How it works:
  1. Check operator’s token balance
  2. Protocol share = accumulatedProtocolFees[token] (tracked per-token)
  3. Operator share = remaining balance
  4. Transfer protocol share to protocolFeeRecipient
  5. Transfer operator share to FEE_RECEIVER
  6. Reset accumulated tracking to 0
distributeFees() is permissionless, anyone can trigger distribution. This stops fees from accumulating indefinitely in the operator.

ProtocolFeeConfig

Shared protocol-level fee governance with built-in safety:

Constants

Calculator Changes (7-Day Timelock)

Recipient Changes (7-Day Timelock)

Operator fees are immutable: set at deploy time via IFeeCalculator and FEE_RECEIVER. Only protocol fees support updates (with 7-day timelock). Already-authorized payments use locked fee rates regardless.

Disabling Protocol Fees

Set the protocol fee calculator to address(0) to disable protocol fees entirely. The operator will calculate 0 bps for the protocol layer.

FEE_RECEIVER Roles

The operator’s FEE_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.