Overview
This tutorial walks you through executing your first x402 payment from start to finish. You’ll learn how to:- Set up your wallet with USDC on Cronos Testnet
- Make a payment-protected API request
- Handle the 402 response
- Generate and submit payment
- Retry with entitlement
Prerequisites
1. Wallet Setup
1. Wallet Setup
Install MetaMask or any Web3 wallet:
2. Add Cronos Testnet
2. Add Cronos Testnet
Add Cronos Testnet to your wallet:
| Field | Value |
|---|---|
| Network Name | Cronos Testnet |
| RPC URL | https://evm-t3.cronos.org |
| Chain ID | 338 |
| Currency Symbol | TCRO |
| Block Explorer | https://explorer.cronos.org/testnet |
3. Get Testnet CRO
3. Get Testnet CRO
Get free testnet CRO from faucet:
- Visit Cronos Faucet
- Enter your wallet address
- Receive 10 TCRO for gas fees
4. Get Testnet USDC
4. Get Testnet USDC
Get testnet USDC:
Step-by-Step Tutorial
Step 1: Install Dependencies
Step 2: Initialize Wallet and Facilitator
Step 3: Check USDC Balance
Step 4: Make Protected API Request
Step 5: Handle 402 Response
Step 6: Generate Payment Header
Step 7: Submit Payment for Settlement
Step 8: Retry Request with Payment ID
Step 9: Verify On-Chain
Complete Code Example
Common Issues
Issue 1: Insufficient USDC Balance
Error:Insufficient USDC balance
Solution:
Issue 2: Invalid Signature
Error:Payment verification failed: Invalid signature
Solution:
- Ensure you’re using the correct wallet
- Check that
signerparameter matches wallet - Verify network is Cronos Testnet (338)
Issue 3: Nonce Already Used
Error:Nonce already used
Solution:
- Generate a fresh payment header
- Don’t reuse payment headers
- Each payment needs a unique nonce
Issue 4: Authorization Expired
Error:Authorization expired
Solution:
Next Steps
Session Escrow
Create session for multiple payments
SDK Integration
Use RelayAgent SDK
MCP Tools
Use x402 via MCP server
Build Service
Create paid service