- Router Page - Terminal-style AI command center (
/router) - OpenAI Integration - Connected and working with provided API key
- Clean Navigation - Updated all pages with "Router" link
- x402 Documentation - Comprehensive docs page explaining the protocol
- Professional Design - cigol.ai inspired theme throughout
Based on the x402-main repository examination, here's what needs to be implemented:
cd valyn-core
npm install x402 viem @solana/kitThe router (/router endpoint) should require x402 payment to access. Implementation needed:
// In server.js
const { paymentMiddleware } = require('x402-express');
// Apply x402 payment to router endpoint
app.use('/api/router', paymentMiddleware(
'0xYOUR_WALLET_ADDRESS', // Where to receive payments
{
price: '$0.01', // Price per request (in USDC)
network: 'base-sepolia', // Test network (or 'base' for mainnet)
config: {
description: 'Access to AI Router commands',
maxTimeoutSeconds: 60
}
},
{
// Facilitator config - defaults to x402.org/facilitator
url: 'https://x402.org/facilitator'
}
));Create /payment page that shows:
- x402 payment requirements
- Wallet connection (MetaMask/WalletConnect)
- QR code for mobile wallets
- Payment status tracking
- Transaction history
Similar to x402.rocks payment flow:
- Connect Wallet
- Approve USDC spending (one-time)
- Sign payment authorization (EIP-3009)
- Access granted automatically
Add to router.js:
// Check if payment is required
const response = await fetch('/api/router', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ prompt, systemMessage })
});
if (response.status === 402) {
// Payment required
const paymentRequirements = await response.json();
// Show payment modal
await showPaymentModal(paymentRequirements);
// After payment, retry with X-PAYMENT header
const paymentPayload = await createPaymentPayload(paymentRequirements);
const paidResponse = await fetch('/api/router', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-PAYMENT': paymentPayload
},
body: JSON.stringify({ prompt, systemMessage })
});
}Add wallet connection library:
npm install wagmi viem @rainbow-me/rainbowkitCreate wallet connector component for:
- MetaMask
- WalletConnect
- Coinbase Wallet
- Display balance
- Sign payment authorizations
Create these pages to educate users:
- Visual flow diagram
- Step-by-step explanation
- Benefits vs traditional payments
- Security guarantees
- Current router pricing ($0.01/request)
- Bulk purchase options
- Subscription alternatives
- Enterprise pricing
- How to install MetaMask
- How to get testnet BNB/USDC
- How to approve token spending
- Troubleshooting common issues
Add to homepage:
- Payment statistics (total spent, requests made)
- Transaction history
- Quick wallet connection widget
- Balance display
# Server
PORT=3000
OPENAI_API_KEY=sk-proj-...
PAYMENT_WALLET_ADDRESS=0x... # Your BNB Chain wallet
NETWORK=base-sepolia # or 'base' for mainnet
# Client (for testing)
TEST_WALLET_PRIVATE_KEY=0x... # For development onlyBNB Chain Testnet (Chain ID: 97)
- USDC Token: Need to deploy or use existing
- x402 Facilitator: Use x402.org/facilitator
BNB Chain Mainnet (Chain ID: 56)
- USDC Token: 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d
- x402 Facilitator: Use x402.org/facilitator or self-host
valyn-core/
├── public/
│ ├── index.html (Dashboard)
│ ├── router.html (AI Router - requires payment)
│ ├── docs.html (Documentation)
│ ├── payment.html (Payment flow explanation)
│ ├── how-it-works.html (x402 education)
│ ├── pricing.html (Pricing tiers)
│ ├── wallet-setup.html (Wallet guide)
│ ├── styles.css
│ ├── script.js
│ ├── router.js
│ ├── payment.js (Payment handling)
│ └── wallet.js (Wallet connection)
├── server.js (x402 middleware integrated)
├── package.json (with x402 dependencies)
└── .env (wallet addresses, API keys)
-
Get testnet tokens:
- BNB testnet faucet: https://testnet.bnbchain.org/faucet-smart
- USDC testnet tokens: Deploy mock or use existing
-
Configure wallet:
// In payment.js const config = { network: 'bsc-testnet', chainId: 97, rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/' };
-
Test payment flow:
- Connect wallet
- Request router access
- Sign payment
- Verify access granted
-
Switch to mainnet:
- Update
NETWORK=basein .env - Use real BNB Chain (Chain ID: 56)
- Use production USDC contract
- Update
-
Set real pricing:
price: '$0.01', // or higher for production
-
Monitor transactions:
- Add transaction logging
- Set up payment webhooks
- Track user balances
- Never expose private keys - Use environment variables
- Validate payment signatures - Use x402 verify endpoint
- Rate limiting - Prevent abuse even with payment
- Session management - Track paid sessions
- Error handling - Graceful payment failures
✅ Zero Platform Fees - Direct wallet-to-wallet payments ✅ Instant Settlement - ~2 second confirmation on BNB Chain ✅ No Registration - Users pay with any wallet, no signup ✅ AI Agent Ready - Agents can autonomously pay for access ✅ Open Standard - Compatible with entire x402 ecosystem
-
Install Dependencies
npm install x402 x402-express viem @solana/kit wagmi @rainbow-me/rainbowkit
-
Get Wallet Address - Where to receive payments
-
Choose Network - Testnet (bsc-testnet) or Mainnet (bsc)
-
Implement Payment Gate - Add middleware to
/api/router -
Create Payment UI - Wallet connection + payment flow
-
Test End-to-End - Full payment cycle
Would you like me to implement any of these specific components?