HTTP 402 payment integration with Thirdweb on Avalanche Fuji testnet.
git clone https://github.com/federiconardelli7/x402-starter-kit.git
cd x402-starter-kit
npm install- Go to Thirdweb Dashboard
- Log in with your wallet (connect your wallet to the dashboard)
- Create a new project or use an existing one
- Get your Client ID and Secret Key from the project
IMPORTANT: The THIRDWEB_SERVER_WALLET_ADDRESS is the facilitator address used for transaction processing.
You MUST use an ERC4337 Smart Account:
- In the Thirdweb dashboard, go to Server Wallets section
- Click the switch button Show ERC4337 Smart Account
- Switch to the network (for example Avalanche Fuji Testnet)
- Copy the smart account address - this will be your
THIRDWEB_SERVER_WALLET_ADDRESS - Send some testnet token to that address that will pay the gas fee.
IMPORTANT: Do NOT use ERC-7702 accounts. Only ERC4337 Smart Accounts are supported as facilitators for some networks.
Copy .env.example to .env.local:
cp .env.example .env.localFill in the required values:
NEXT_PUBLIC_THIRDWEB_CLIENT_ID- Your Thirdweb client IDTHIRDWEB_SECRET_KEY- Your Thirdweb secret keyTHIRDWEB_SERVER_WALLET_ADDRESS- Facilitator address (ERC4337 Smart Account address)MERCHANT_WALLET_ADDRESS- Payment recipient wallet addressOPENROUTER_API_KEY- Your OpenRouter API key for AI chat (Get one here)
npm run devnpm run build
npm start- HTTP 402 payment protocol implementation
- Two payment tiers (Basic: $0.01, Premium: $0.15)
- Automatic signature normalization for Avalanche Fuji
- Real-time transaction logging
- Token-Based AI Chat: Pay-per-use LLM chatbot based on actual token usage ($0.001 per 1K tokens, max $0.50 per message)
- Autonomous AI Agent: Pre-authorize a budget for an AI agent to autonomously interact with services and pay with x402 protocol (e.g., cryptocurrency price lookups at $0.02 per call)
- Modern interface with shadcn components
- Mode switcher between Human Payment and AI Agents
- Real-time payment tracking and transaction logs
- Next.js 16
- Thirdweb SDK v5
- TypeScript
- Tailwind CSS
- shadcn/ui components