A blockchain-based pay-per-execution service implementing the x402 protocol (HTTP 402 Payment Required). Users pay with U tokens (or signature-based payment) on Base Sepolia to execute jobs, with results streamed back in real-time.
Powered by: LayerZero Β· Privy Β· Coinbase Base Β· x402
Live demo at: https://x402.utils.com/
Status: β Production-ready PoC Β· All tests passing Β· Multiple frontends Β· Python agent
This project showcases the integration of three powerful blockchain infrastructure providers:
π LayerZero
Omnichain Interoperability Protocol - Powers the U token with seamless cross-chain transfers between Ethereum and Base. No wrapped tokens, no bridges to trustβjust native cross-chain fungibility.
π Privy
Embedded Wallet Infrastructure - Provides frictionless web3 onboarding with social logins, embedded wallets, and delegated transaction signing. Users can interact with blockchain apps without managing private keys.
π³ Coinbase
Enterprise Blockchain Platform - Leverages Base L2 for high-performance, low-cost transactions. Base provides the scalability needed for microtransactions in the x402 protocol.
Why This Stack?
- LayerZero: Cross-chain liquidity without fragmentation
- Privy: Web2-level UX for web3 applications
- Base (Coinbase): Production-ready L2 with institutional backing
x402 web interface executing a ping job with real-time streaming results
Payment Flows:
- Traditional: User β 402 Response β ERC20 Transfer β Payment Verified β Job Executes β Results Stream
- x402 Signature: User β Sign EIP-712 β X-PAYMENT Header β Instant Authorization β Job Executes β Results Stream
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββ
β 2 Frontends ββββββΆβ FastAPI Backend ββββββΆβ Base Sepolia β
β + 1 Agent βββββββ (x402 Server) βββββββ Blockchain β
βββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββββ
β’ Vanilla JS β’ Payment verify β’ U Token (ERC20)
β’ React + Privy β’ EIP-712 sigs β’ Payment tracking
β’ Python Agent β’ SSE streaming β’ Smart contracts
The x402 protocol uses U Token, a custom ERC20 token built with LayerZero's Omnichain Fungible Token (OFT) standard. This enables seamless cross-chain transfers between networks.
- Ethereum (Sepolia): Primary network for liquidity and token minting
- Base (Sepolia): Optimized for high-performance, low-cost transactions
- LayerZero Bridge: Automatic token bridging between chains in ~5-10 minutes
A public testnet faucet is available for anyone to experiment with the x402 protocol:
- Faucet Address:
0x63b7eF0778143E23f7320ab5bB77344aE66e7a57(Base Sepolia) - Distribution: 1 U token per address per day
- Purpose: Free tokens for testing and development
- Explorer: View on Blockscout
U Token Addresses:
- Sepolia:
0x3edEa36d049fFeF9Ac3fC3646227ca81C9A87118 - Base Sepolia:
0x7143401013282067926d25e316f055fF3bc6c3FD
For more details on the U token and faucet management, see the u-layerzero/ and u-faucet/ directories.
./start.shThis automatically starts:
- β Backend on http://localhost:8989
- β Frontend-JS on http://localhost:3000 (Vanilla JS + MetaMask)
- β Frontend-Privy on http://localhost:3001 (React + Privy + x402)
-
Configure backend:
cd x402-backend cp .env.example .env # Edit .env: RECIPIENT_ADDRESS=0xYourWalletAddress
-
Run backend:
cd x402-backend python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt python main.py
-
Choose your frontend:
Option A: Vanilla JS (MetaMask/Coinbase Wallet)
cd x402-js python -m http.server 3000 # Visit: http://localhost:3000
Option B: React + Privy (Recommended - Full x402)
cd x402-privy npm install npm run dev # Visit: http://localhost:3001
-
Or run the Python agent:
cd x402-agent pip install -r requirements.txt python x402_agent.py # Pings google.com every 3 minutes
| Feature | Frontend-JS (3000) | Frontend-Privy (3001) β | Agent |
|---|---|---|---|
| Tech | Vanilla JS | React + Privy | Python |
| Wallet | MetaMask/Coinbase | Privy Embedded | Generated |
| Payment | ERC20 Transfer | x402 + Traditional | x402 Signature |
| Auto-Approve | β No | β Yes (Delegation) | N/A |
| x402 Protocol | β No | β Full Support | β Yes |
| Best For | Testing basics | Production use | Automation |
| Setup | None | npm install |
pip install |
Recommendation: Use Frontend-Privy (3001) for full x402 features and best UX.
- Dual payment support: Traditional ERC20 transfers + x402 signature-based
- EIP-712 verification: Validates signed payment authorizations
- Extensible job system: Plugin-based registry for easy job type additions
- Payment verification: Monitors Base Sepolia for ERC20 Transfer events
- Real-time streaming: Server-Sent Events (SSE) for live output
- Timeout management: 5-minute configurable payment windows
1. Frontend-JS (Port 3000)
- Vanilla JavaScript with Web3.js
- MetaMask/Coinbase Wallet integration
- Traditional ERC20 payment flow
- Asta framework monospace UI
- No build process required
2. Frontend-Privy (Port 3001) β Recommended
- React + TypeScript with Vite
- Privy embedded wallet support
- Full x402 signature-based payment
- Delegated actions for auto-approve
- Dual payment method (x402 + traditional)
- Best developer experience
3. Python Agent
- Autonomous x402 client
- Periodic job execution
- EIP-712 signature creation
- No blockchain transaction needed
- Perfect for automation/monitoring
- Network: Base Sepolia (Chain ID: 84532)
- RPC: https://base-sepolia-rpc.publicnode.com
- Token: U at
0x7143401013282067926d25e316f055fF3bc6c3FD - Pricing: 0.01 U per ping
- Payment timeout: 300s (configurable via
PAYMENT_TIMEOUTenv var)
| Endpoint | Method | Description | Response |
|---|---|---|---|
/ |
GET | Health check | Service status |
/api/jobs |
GET | List available jobs | Jobs with pricing |
/api/jobs/request |
POST | Request job execution | 402 with payment details |
/api/jobs/verify-payment |
POST | Verify blockchain payment | Verification status |
/api/jobs/execute/{id} |
GET | Execute paid job | SSE stream |
/api/jobs/status/{id} |
GET | Check job status | Job state |
Create a job class inheriting from Job:
# x402-backend/jobs/my_job.py
from decimal import Decimal
from .base import Job
class MyJob(Job):
@classmethod
def get_name(cls) -> str:
return "my_job"
@classmethod
def get_price(cls) -> Decimal:
return Decimal("0.05")
def validate_params(self) -> tuple[bool, str]:
# Validate self.params
return True, ""
async def execute(self) -> AsyncIterator[str]:
yield "Starting...\n"
# ... do work ...
yield "Complete!\n"Register in x402-backend/jobs/registry.py:
from .my_job import MyJob
class JobRegistry:
def _register_default_jobs(self):
self.register(PingJob)
self.register(MyJob) # Add thisDate: 2025-11-22 Β· Status: β All tests passed
- β Backend: Server startup, Base Sepolia connection (no warnings)
- β
API: 7/7 endpoint tests passed
- Health check, job listing, x402 flow, status, execution blocking
- Input validation, error handling
- β Jobs: Ping execution successful (8.8.8.8, 0% packet loss)
- β Protocol: Complete x402 flow verified (request β 402 β verify β execute)
- β Code: Python 3.12+ compatible, timezone-aware, lifespan context manager
- β Network: Base Sepolia RPC connected, token contract accessible
Environment: Linux Β· Python 3.12.12 Β· FastAPI 0.109.0 Β· Web3.py 6.15.1
- Job result caching and storage
- User accounts and history
- Webhook notifications
- Comprehensive test suite
MIT License
- LayerZero Docs - Omnichain interoperability protocol
- LayerZero Scan - Track cross-chain transactions
- Privy Docs - Embedded wallet infrastructure
- Base Docs - Coinbase L2 documentation
- Base Sepolia Explorer - Block explorer
- Base Faucet - Get testnet ETH
- FastAPI Docs - Python web framework
- Web3.py Docs - Python Ethereum library
We'd love to hear from you! This project is open for ideas, suggestions, and contributions.
- π‘ Ideas: Have a feature idea or improvement suggestion? We want to hear it!
- π Issues: Found a bug or something not working as expected? Let us know!
- π¬ Feedback: General comments, questions, or thoughts about the x402 protocol? Reach out!
- π€ Contributions: Pull requests are welcome! Whether it's code, documentation, or examples.
-
Share Use Cases. Show us what you've built or plan to build with the x402 protocol.
-
Open an issue on this repository or submit a pull request. All contributions and feedback are appreciated! π