Overview
x402r adds escrow, refund windows, and dispute resolution on top of the Commerce Payments Protocol. Below you’ll find the measured gas cost of every on-chain operation so you can weigh the overhead. All numbers come from Foundry simulations (forge test --gas-report) with optimizer enabled (200 runs, via IR), pinned to x402r-contracts @ bb188db (snapshot: 2026-05-20). The benchmark lives at test/gas/GasBenchmark.t.sol. Numbers are per-transaction and warm where the test measures warm (so they reflect typical second-and-beyond payments on the same operator); cold-vs-warm splits are reported alongside the warm number where relevant.
The buyer never pays gas. They only sign an off-chain ERC-3009 or Permit2 authorization. The facilitator, merchant, or another party submits every on-chain transaction.
What you’ll pay on Base
Disputes are rare and add < $0.005 with off-chain resolution, see Dispute Path below.
Happy Path
The happy path has 2 on-chain transactions:authorize (at checkout) and capture (after the escrow period expires). With operator fees enabled, the distributeFees() call adds a third settle-time write to claim accumulated protocol fees, batched across many payments.
The vs transfer column shows multiples of a cold ERC-20
transfer() (10,263 gas), the absolute floor for moving tokens on-chain.
In production, the merchant typically calls capture(), but the function has no caller restriction beyond the configured capture condition (EscrowPeriod + Freeze). After the escrow period passes and the payment isn’t frozen, anyone can trigger it.
An escrow authorization is inherently more work than a raw ERC-20 transfer: it validates payment info, checks fee bounds, locks fees, transfers tokens into escrow, and records state. The per-plugin section below shows exactly where the gas goes.
Per-Plugin Gas Costs
The PaymentOperator runs with pluggable conditions (checked before an action) and hooks (called after). You choose which plugins to use. Here’s the marginal cost of each, measured by diffing adjacent configurations through thePaymentOperator entry point.
authorize()
The EscrowPeriod hook is the single most expensive plugin on
authorize because it writes to a new storage slot in the EscrowPeriod contract.
capture()
Dispute Path
These operations only happen when a buyer disputes a payment. Most payments never touch this path.Off-chain resolution
The refund request, evidence submission, and arbiter approval can all happen off-chain. The only on-chain steps arefreeze() (to lock the payment during the escrow window) and void() (to return funds). The arbiter never submits a transaction; their approval is an EIP-712 signature that anyone can relay.
Total dispute cost on Base with off-chain resolution: < $0.005.
Fully on-chain fallback
If the parties choose to handle the dispute fully on-chain instead:
This total includes the happy path steps (
authorize + capture) since those already ran. The dispute-only overhead is 665,001 gas (< $0.02 on Base).
Why is requestRefund so expensive?
Why is requestRefund so expensive?
requestRefund() at 418,174 gas is the most expensive operation because it writes to five storage mappings for indexing:- Refund request data (status, amount, payment hash)
- Payer index (
payerRefundRequests[payer][n]) - Receiver index (
receiverRefundRequests[receiver][n]) - Operator index (
operatorRefundRequests[operator][n]) - Counter increments for each index
Summary
The full x402r happy path uses ~32x the gas of a single ERC-20 transfer, but on Base L2, the absolute cost stays under a penny. The overhead comes from escrow validation, fee locking, cross-contract storage writes, and condition checks, all detailed in the per-plugin breakdown above.
All numbers above assume one payment per transaction. Batching operations in a single transaction (via a multicall contract) can reduce per-payment costs by 37 to 80 percent thanks to warm EVM access; contract addresses and shared storage only load once. The benchmark test includes warm measurements for reference.
Reproducing these numbers
console.log and the --gas-report summary tables list aggregate per-function statistics.
A scheduled CI job in x402r-contracts re-runs
GasBenchmark.t.sol and flags drift past threshold, so the numbers on this page are checked against the live benchmark rather than left to manual regen. When the benchmark moves, the pinned commit and figures above are refreshed.Reference: upstream escrow costs
The escrow layer these numbers build on is Base’s audited Commerce Payments Protocol. For the baseline cost of the underlyingAuthCaptureEscrow lifecycle (authorize, capture, void, refund) independent of x402r’s condition and hook plugins, see the upstream contracts and their own benchmarks in the commerce-payments repository. The x402r figures above are the upstream escrow cost plus the per-plugin overhead detailed in the breakdown.
Fee System
How the operator calculates and distributes protocol and operator fees
Architecture
How conditions, hooks, and escrow fit together
