A fully functional x402 payment demo that wraps the existing 0G Serving SDK with zero changes to core code.
Demo URL: http://localhost:3001/x402-demo
Console: Press F12 to see x402 payment flow
X402BrokerWrapper class that:
- ✅ Simulates x402 payment authorization
- ✅ Generates EIP-712-compatible structure
- ✅ Logs full payment flow to console
- ✅ Manages simulated USDC balance
- ✅ Wraps existing
broker.ledger.depositFund()
Size: 170 lines Dependencies: ethers (already installed)
Export file for x402 module.
Size: 1 line
React hook for demo functionality:
- ✅ Initializes x402 wrapper
- ✅ Manages deposit state
- ✅ Handles x402 and traditional deposits
- ✅ Auto-refreshes balances
Size: 85 lines Dependencies: React, wagmi, ethers (all existing)
Full demo page with:
- ✅ Side-by-side comparison cards
- ✅ Balance display (Ledger + USDC + Total)
- ✅ Payment method selector
- ✅ Deposit interface
- ✅ Success/error messages
- ✅ Info section with disclaimers
Size: 320 lines Dependencies: React, Next.js (all existing)
Added navigation link to x402 demo:
<Link href="/x402-demo" className="...">
⚡ x402 Demo
</Link>Change: +3 lines Impact: Minimal - only adds navigation
- ✅
src.ts/- SDK source code (untouched) - ✅ Smart contracts (no changes)
- ✅
src/app/inference/- Inference pages (untouched) - ✅
src/app/wallet/- Wallet page (untouched) - ✅
src/app/fine-tuning/- Fine-tuning page (untouched) - ✅
src/shared/hooks/use0GBroker.ts- Core broker hook (untouched) - ✅ All other components (untouched)
Total Impact: Isolated to 4 new files + 1 navbar link
User Interface (/x402-demo)
↓
useX402Demo Hook
↓
X402BrokerWrapper (Simulates x402)
↓
Existing SDK (NO CHANGES)
↓
Smart Contracts (NO CHANGES)
Key Point: Wrapper intercepts calls, simulates x402 flow, then uses existing SDK methods.
- Traditional vs x402 feature comparison
- Cost comparison ($2 vs $0)
- Requirements comparison (A0GI vs USDC)
- Live balance display
- Payment method toggle
- Real-time updates
- Error handling
🔷 x402 Payment Flow Started
📝 Generating x402 payment authorization...
✅ Payment authorization generated
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔷 x402 Payment Authorization
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Protocol: x402
Version: 1.0
From: 0x742d35Cc...
To: 0x09D00A2B...
Amount: 10000000
Token: USD Coin
Valid Until: 1/3/2025, 3:45:30 PM
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
💳 Executing payment via x402...
✅ x402 payment successful!
💰 Remaining USDC balance: 990
- Server running (
npm run dev) - Browser open to http://localhost:3001/x402-demo
- Wallet connected to 0G testnet
- Console open (F12)
- Page loads without errors
- Balances display correctly
- Select x402 payment method
- Enter amount (e.g., 10)
- Click deposit
- Console shows payment flow
- Success message appears
- Balances update
- USDC balance decrements
- Select traditional method
- Enter amount
- Click deposit
- Transaction processes (needs A0GI)
- Balance updates
- Navigate to /inference (should work normally)
- Navigate to /wallet (should work normally)
- Navigate to /fine-tuning (should work normally)
- Connect/disconnect wallet (should work normally)
- Lines Added: ~576 lines (4 new files)
- Lines Modified: 3 lines (1 file)
- Files Created: 4
- Files Modified: 1
- Files Deleted: 0
- Build Time: ~25 seconds (unchanged)
- Bundle Size: +~15KB
- Dependencies: 0 new (uses existing)
- Existing Features: 0% changed
- New Features: 1 (x402 demo)
- Breaking Changes: 0
- Deprecations: 0
- Open http://localhost:3001/x402-demo
- Connect wallet
- Select payment method
- Enter amount
- Click deposit
- Watch magic happen ✨
// Import wrapper
import { X402BrokerWrapper } from '@/lib/x402'
// Create wrapper
const wrapper = new X402BrokerWrapper(broker, signer)
// Deposit via x402
await wrapper.depositViaX402(10, 'USDC')
// Check balance
const balance = wrapper.getUSDCBalance()- Show comparison cards (Traditional vs x402)
- Explain benefits (gasless, USDC, multi-chain)
- Perform live deposit
- Show console output
- Highlight balance updates
- USDC balance is simulated (not on-chain)
- Signatures are mocked (not real EIP-712)
- Uses existing deposit method underneath
- No smart contract changes
To make this production-ready:
- Replace mock signatures with real EIP-712
- Implement ERC-3009
receiveWithAuthorization - Update
LedgerManagercontract - Connect to real USDC/DAI contracts
- Add proper error handling
- Security audit
Estimated Time: 2-3 weeks
✅ Fast: Shipped in 3 days ✅ Safe: Zero impact on existing code ✅ Isolated: Easy to remove if not approved ✅ Functional: Demonstrates full flow ✅ Educational: Shows x402 structure
✅ Validation: Proves concept before major work ✅ Feedback: Get stakeholder input early ✅ Architecture: Framework is ready ✅ Buy-in: Visual demo helps approval
Q: Is this production-ready? A: No, this is a demo/MVP. See "Production Implementation Required" above.
Q: Does it change the SDK? A: No, it's a wrapper. SDK code is untouched.
Q: Can I use real USDC? A: Not yet. Need smart contract changes first.
Q: Will other pages still work? A: Yes, 100%. This is completely isolated.
Q: How do I remove this? A: Delete 4 files, remove navbar link. Done.
Issue: Console not showing output Fix: Press F12, check Console tab
Issue: Wallet won't connect Fix: Check you're on 0G testnet, refresh page
Issue: Deposit fails Fix: Check you have A0GI for gas, check amount > 0
Issue: Page won't load Fix: Check server is running, correct port
Demo is successful if:
- Stakeholders can see x402 flow
- Console output is clear and educational
- Comparison shows value proposition
- No bugs or errors
- Existing features unaffected
- Gets approval for full implementation
- Plan full implementation
- Create production issues/PRs
- Implement real EIP-712 signatures
- Update smart contracts
- Add ERC-3009 support
- Security audit
- Testnet deployment
- Mainnet launch
- Gather feedback
- Update demo
- Re-present
- Iterate
- Remove 4 files
- Remove navbar link
- Delete this branch
- No harm done!
After testing, please provide:
First Impression:
- Excellent
- Good
- Needs Improvement
Console Output:
- Clear and helpful
- Too verbose
- Confusing
Value Proposition:
- Very clear
- Somewhat clear
- Not clear
Approval:
- Approve for production implementation
- Needs changes (specify below)
- Reject
Comments: Your feedback here...
Status: ✅ Complete and Ready Build: ✅ Successful Server: ✅ Running on :3001 Impact: ✅ Zero on existing features Risk: ✅ Minimal (isolated)
Demo URL: http://localhost:3001/x402-demo
Ready to test! 🚀
Last Updated: November 3, 2025 Version: 1.0 (MVP Demo) Status: Ready for Testing