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):
Pre-Settlement Enforcement
Why collect fee BEFORE settlement?- Prevents free service: Merchants cannot exploit failed settlements
- Guarantees payment: Facilitator only executes if paid
- Atomic guarantee: Fee collection failure blocks settlement
- Economic sustainability: Every settlement attempt costs merchant
ERC-20 Approval Pattern
Standard pattern used across DeFi:- ✅ 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:Step 2: Client Requests Resource
Client makes GET request to protected endpoint:Step 3: Merchant Returns 402
Server responds with payment requirements: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: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
- Standard ERC-20 approval (revocable anytime)
- Exact fee amount known upfront ($0.01)
- On-chain auditable
- Fee collected BEFORE settlement executes
- No fee = no settlement (guaranteed)
- Prevents free service exploitation
- 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)
- Flat $0.01, no dynamic pricing or hidden fees
- Approval limits what facilitator can collect
- Pre-settlement fee collection guarantees payment
Security Considerations
Approval Safety
Merchant controls:- Approval amount - Decide how many settlements to fund
- Revocation - Can revoke approval anytime via:
- Monitoring - Check remaining allowance:
| Scenario | Protection |
|---|---|
| Facilitator drains entire USDC balance | ❌ Impossible - only approved amount accessible |
| Facilitator collects more than $0.01 | ❌ Blocked by smart contract (exact amount hardcoded) |
| Facilitator redirects customer funds | ❌ Impossible - EIP-3009 signature bound to merchant |
| Merchant has insufficient approval | ✅ Settlement blocked, customer not charged |
| Settlement fails after fee collection | ⚠️ Merchant paid for attempt (prevents free service) |
Settlement Atomicity
Pre-settlement fee collection ensures:- Fee collected FIRST
- If fee fails → settlement blocked, customer not charged
- If settlement fails → fee already collected (payment for service)
- Pre-settlement: Fee collection failure = no settlement = customer safe
- Post-settlement (rejected): Settlement could succeed but fee fail = free service
Comparison: Pre-Settlement vs Post-Settlement
| Aspect | Pre-Settlement (Current) | Post-Settlement (Rejected) |
|---|---|---|
| Fee collection timing | BEFORE settlement ✅ | AFTER settlement |
| Free service risk | Zero (fee first) ✅ | High (could fail fee collection) |
| Customer protection | High (no fee = no charge) ✅ | Lower (could be charged with failed fee) |
| Merchant risk | Pays for attempt | Lower fee risk |
| Economic sustainability | Guaranteed ✅ | Exploitable |
| Trust minimization | Maintained ✅ | Maintained |
- Prevents free service exploitation
- Guarantees facilitator payment
- Customer never charged if fee collection fails
- Economically sustainable business model
Comparison: Old vs Current Architecture
| Aspect | Treasury-First (Old) | Pre-Settlement (Current) |
|---|---|---|
| Customer payment | → Treasury → Merchant | → Merchant (direct) ✅ |
| Fee collection | Atomic split | Pre-settlement via transferFrom ✅ |
| Trust required | High (custody) | Minimal (approval only) ✅ |
| x402 compliant | ❌ No | ✅ Yes |
| Merchant setup | None | One-time approval |
| Revocability | Not applicable | Standard ERC-20 revoke ✅ |
| Free service risk | N/A | Eliminated ✅ |
Implementation Details
On-Chain Transactions
Setup (One-Time):Error Handling
Insufficient Allowance: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
- ❌ 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:insufficient_allowance error at the pre-settlement fee collection step.
Best Practices
Approve Reasonable Amounts
Approve Reasonable Amounts
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.
Monitor Allowance
Monitor Allowance
Set up alerts when allowance drops below threshold:
Test on Sepolia First
Test on Sepolia First
Always test approval and settlements on Base Sepolia before mainnet:
Maintain USDC Balance
Maintain USDC Balance
Ensure merchant address has USDC for fee payment:
- Minimum: 1 USDC (100 settlements)
- Recommended: Match approval amount
FAQ
Why collect fee BEFORE settlement instead of after?
Why collect fee BEFORE settlement instead of after?
Economic security: Pre-settlement prevents free service exploitation.Without pre-settlement: Merchants could:
- Receive customer payment
- Intentionally cause fee collection to fail
- Get free verification/settlement service
What if settlement fails after fee collection?
What if settlement fails after fee collection?
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
Can facilitator drain my USDC balance?
Can facilitator drain my USDC balance?
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
What happens if I have insufficient USDC for the fee?
What happens if I have insufficient USDC for the fee?
Settlement is blocked at pre-settlement fee collection step.Flow:
- Customer submits payment authorization
- Facilitator attempts fee collection
- Fee collection fails (insufficient balance)
- Settlement NEVER executes
- Customer NOT charged
fee_collection_failed - Settlement blockedHow is pre-settlement different from post-settlement?
How is pre-settlement different from post-settlement?
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.