Skip to main content

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
Time to complete: 10 minutes

Prerequisites

Install MetaMask or any Web3 wallet:
Add Cronos Testnet to your wallet:
Get free testnet CRO from faucet:
  • Visit Cronos Faucet
  • Enter your wallet address
  • Receive 10 TCRO for gas fees
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 signer parameter 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