Skip to main content

Overview

0xmeta uses pre-settlement fee collection to maintain x402’s core principle: trust minimization. Customer funds flow directly to merchants—never through the facilitator. Fees are collected before settlement via standard ERC-20 approval patterns.
Trust-Minimized with Pre-Settlement: Customer payments go DIRECTLY to merchants. The facilitator collects the $0.01 fee from the merchant’s pre-approved balance BEFORE executing the settlement. If fee collection fails, settlement is blocked.

Payment Architecture

Trust-Minimized Flow with Pre-Settlement Fee Collection

Key Principle: Fee collected FIRST (orange), then customer payment executes (blue). Customer funds go DIRECTLY to merchant. No fee = no settlement.

Why This Architecture?

x402 Trust-Minimization Requirement

From x402 specification:
“The facilitator must never have custody or control over customer payments. All funds must flow directly from payer to payee.”
Previous approach (REJECTED):
Current approach (APPROVED):

Pre-Settlement Enforcement

Why collect fee BEFORE settlement?
  1. Prevents free service: Merchants cannot exploit failed settlements
  2. Guarantees payment: Facilitator only executes if paid
  3. Atomic guarantee: Fee collection failure blocks settlement
  4. Economic sustainability: Every settlement attempt costs merchant
Trade-off: Merchant pays $0.01 even if settlement fails after fee collection. Rationale: This is payment for the verification and settlement attempt service. Without this, merchants could intentionally cause settlement failures for free verification.

ERC-20 Approval Pattern

Standard pattern used across DeFi:
Benefits:
  • ✅ Standard ERC-20 pattern (well understood)
  • ✅ Merchant controls via approval amount
  • ✅ Auditable on-chain
  • ✅ Can revoke anytime (settlements will fail)
  • ✅ Fee collection happens first (no free rides)

Payment Flow Details

Step 1: One-Time Merchant Approval

Merchant approves facilitator treasury for USDC spending:
Approval amount = settlements * $0.01 Example: 100 USDC approval = 10,000 settlements

Step 2: Client Requests Resource

Client makes GET request to protected endpoint:

Step 3: Merchant Returns 402

Server responds with payment requirements:
Critical: payTo must be merchant address, NOT treasury.

Step 4: Client Creates Authorization

Client signs EIP-3009 authorization to merchant:

Step 5: Facilitator Verification

Facilitator validates authorization cryptographically:

Step 6: Pre-Settlement Fee Collection

BEFORE executing customer payment, facilitator collects fee:
Critical: If fee collection fails at this step, settlement is blocked. Customer is NOT charged. This guarantees the facilitator never provides free service.

Step 7: Settlement Execution (After Fee)

After fee successfully collected, execute customer → merchant payment:

Trust Model

What Merchants Trust

Customer payments arrive directly
  • EIP-3009 authorization cryptographically bound to merchant address
  • Facilitator cannot redirect customer funds
  • 100% of customer payment received
Fee collection is explicit and controllable
  • Standard ERC-20 approval (revocable anytime)
  • Exact fee amount known upfront ($0.01)
  • On-chain auditable
Pre-settlement enforcement
  • Fee collected BEFORE settlement executes
  • No fee = no settlement (guaranteed)
  • Prevents free service exploitation
No custody risk
  • Facilitator never holds customer funds
  • Settlement executes customer → merchant directly

What Merchants Don’t Need to Trust

Facilitator custody
  • Never happens (funds go direct to merchant)
Fee calculation
  • Flat $0.01, no dynamic pricing or hidden fees
Arbitrary fund movement
  • Approval limits what facilitator can collect
Settlement execution without payment
  • Pre-settlement fee collection guarantees payment

Security Considerations

Approval Safety

Merchant controls:
  1. Approval amount - Decide how many settlements to fund
  2. Revocation - Can revoke approval anytime via:
  3. Monitoring - Check remaining allowance:
Attack scenarios:

Settlement Atomicity

Pre-settlement fee collection ensures:
  1. Fee collected FIRST
  2. If fee fails → settlement blocked, customer not charged
  3. If settlement fails → fee already collected (payment for service)
Critical difference from post-settlement:
  • Pre-settlement: Fee collection failure = no settlement = customer safe
  • Post-settlement (rejected): Settlement could succeed but fee fail = free service
Trade-off: Merchant pays fee even if settlement fails after fee collection. Economic justification: Merchant received verification and settlement attempt services worth $0.01. This prevents exploitation via intentional settlement failures.

Comparison: Pre-Settlement vs Post-Settlement

Why pre-settlement wins:
  1. Prevents free service exploitation
  2. Guarantees facilitator payment
  3. Customer never charged if fee collection fails
  4. Economically sustainable business model

Comparison: Old vs Current Architecture


Implementation Details

On-Chain Transactions

Setup (One-Time):
Per Settlement:
Total merchant gas cost: $0 (after initial approval)

Error Handling

Insufficient Allowance:
Fee Collection Failed (Pre-Settlement):

Alternatives Considered

1. Post-Settlement Fee Collection

Collect fee AFTER executing customer → merchant payment. Why rejected:
  • ❌ Merchants can exploit failed fee collection for free service
  • ❌ Race condition between settlement and fee collection
  • ❌ Customer could be charged even if fee collection fails
  • ❌ Economically unsustainable (free service exploitation)

2. Smart Contract Atomic Split

Why rejected:
  • ❌ Requires custom smart contract deployment
  • ❌ Higher gas costs (contract interaction)
  • ❌ Still requires customer to authorize contract (not direct to merchant)
  • ❌ Violates trust-minimization (contract has custody)

3. Merchant Voluntary Fee Payment

Merchant manually pays fees after receiving customer payment. Why rejected:
  • ❌ Merchants can skip payment (free service)
  • ❌ No enforcement mechanism
  • ❌ Unsustainable business model

4. Treasury-First (Original)

See comparison above. Why rejected:
  • ❌ Violates x402 trust-minimization
  • ❌ Facilitator custody of customer funds
  • ❌ Rejected by Coinbase x402 ecosystem

Monitoring & Operations

Check Allowance

Merchants can monitor remaining allowance:

Top Up Allowance

When allowance runs low:

Revoke Access

To stop allowing settlements:
Effect: All future settlements will fail with insufficient_allowance error at the pre-settlement fee collection step.

Best Practices

Recommended: 100-1000 USDC (10,000-100,000 settlements)Avoid: Infinite approval (max uint256)Why: Limits exposure if facilitator compromised. With pre-settlement, you only risk the approved amount.
Set up alerts when allowance drops below threshold:
Always test approval and settlements on Base Sepolia before mainnet:
Ensure merchant address has USDC for fee payment:
  • Minimum: 1 USDC (100 settlements)
  • Recommended: Match approval amount
Pre-settlement means fee is collected BEFORE settlement, so you need sufficient balance.

FAQ

Economic security: Pre-settlement prevents free service exploitation.Without pre-settlement: Merchants could:
  1. Receive customer payment
  2. Intentionally cause fee collection to fail
  3. Get free verification/settlement service
With pre-settlement: Fee collected first = no free rides.Trade-off: Merchant pays $0.01 even if settlement fails after fee. This is payment for the service attempt.
You paid $0.01 for the settlement attempt.Why this is fair:
  • Facilitator provided verification service
  • Facilitator attempted settlement
  • Resources were consumed
  • Service was rendered
Prevents exploitation: Without charging for attempts, merchants could intentionally fail settlements for free verification.Mitigation: Test thoroughly on Sepolia testnet before production.
No. Only the approved amount is accessible. Pre-settlement doesn’t change this.
  • Approve 100 USDC → max risk is 100 USDC
  • Your remaining USDC: Safe
Settlement is blocked at pre-settlement fee collection step.Flow:
  1. Customer submits payment authorization
  2. Facilitator attempts fee collection
  3. Fee collection fails (insufficient balance)
  4. Settlement NEVER executes
  5. Customer NOT charged
Error: fee_collection_failed - Settlement blocked
Timing and guarantees:Pre-settlement (current):
Post-settlement (rejected):
Pre-settlement eliminates free service risk.

Next Steps

Approve Facilitator

Set up one-time USDC approval

Server Integration

Add x402 middleware to your app

Test Settlement

Complete end-to-end payment flow

Monitor Allowance

Track remaining settlements
Trust-Minimized with Pre-Settlement: Customer funds go DIRECTLY to merchants. Facilitator collects $0.01 fee BEFORE settlement. If fee collection fails, settlement is blocked and customer is never charged. No free rides, fully auditable.