Overview
The x402 facilitator is a critical service in the payment verification flow. It acts as a trusted third party that:- Verifies payment signatures (EIP-712, ERC-6492, EIP-1271)
- Settles transactions on-chain (USDC transfers)
- Returns transaction hashes for proof of payment
Why Use a Facilitator?
Signature Verification
Complex signature validation (ERC-6492 simulation, EIP-1271 calls) handled by the facilitator
On-Chain Settlement
Facilitator submits transactions to the blockchain and manages gas fees
Transaction Abstraction
Host agents don’t need direct blockchain access—just HTTP calls to facilitator
Error Recovery
Facilitator handles nonce management, gas estimation, and transaction retries
Architecture Position
Facilitator Configuration
Fromsrc/constants.ts:
host.ts
Payment Verification Flow
The facilitator handles the complete payment verification pipeline:Step 1: Guest Signs Payment
Guest agent receives 402 response and signs payment:X-PAYMENT header.
Step 2: Host Forwards to Facilitator
Host MCP server extracts signature from header and sends to facilitator:Step 3: Facilitator Verifies Signature
Facilitator performs cryptographic verification:Step 4: Facilitator Settles On-Chain
After signature verification, facilitator submits USDC transfer:Step 5: Host Receives Confirmation
Facilitator returns settlement metadata:Response Format
Fromsrc/agents/guest.ts:354-366:
Facilitator Responsibilities
Signature Verification
Signature Verification
- EIP-712: Recover signer from typed data signature
- ERC-6492: Simulate deployment and verify pre-deployed signatures
- EIP-1271: Call
isValidSignature()on deployed smart contracts - Nonce validation: Ensure nonces are not reused
On-Chain Settlement
On-Chain Settlement
- Gas estimation: Calculate required gas for USDC transfer
- Transaction submission: Broadcast transaction to Base Sepolia
- Confirmation waiting: Wait for block confirmation before returning
- Error handling: Retry failed transactions with adjusted gas
Wallet Deployment
Wallet Deployment
- Deployment detection: Check if wallet exists on-chain
- Auto-deployment: Deploy pre-deployed wallets before first transfer
- Gas funding: Ensure wallet has ETH for gas fees
Security & Validation
Security & Validation
- Amount verification: Ensure signed amount matches request
- Recipient validation: Verify payment goes to correct address
- Network checks: Ensure transaction on correct chain
- Replay protection: Prevent signature reuse via nonce tracking
Running Your Own Facilitator
While the public facilitator athttps://x402.org/facilitator works for development, you may want to run your own for production:
Why Run Your Own?
Control
Full control over verification logic and settlement timing
Privacy
Payment data doesn’t leave your infrastructure
Customization
Add custom validation rules, rate limiting, or analytics
Reliability
No dependency on third-party service availability
Basic Facilitator Implementation
Deployment Checklist
Security Considerations
Nonce Management
Amount Validation
Testing Facilitator Integration
Error Codes
| Code | Error | Cause | Solution |
|---|---|---|---|
| 400 | Invalid signature | Signature verification failed | Check EIP-712 payload matches signed message |
| 400 | Nonce already used | Replay attack detected | Generate new nonce for payment |
| 400 | Insufficient amount | Signed amount < required | Sign with correct payment amount |
| 500 | Settlement failed | Transaction reverted or gas issues | Check wallet has USDC and ETH for gas |
| 503 | RPC unavailable | Blockchain node unreachable | Retry or switch RPC endpoint |
Implementation Checklist
Handle Settlement Metadata
Extract transaction hash from
_meta["x402/payment-response"] in tool results.Related Topics
EIP-712 Signatures
Typed data signing for payments
ERC-6492 Validation
Pre-deployment signature verification
References
- x402 Protocol Specification
- Base Sepolia Explorer
- Source:
events-concierge/src/constants.ts:9 - Source:
events-concierge/src/agents/host.ts:268-272