Skip to main content
This example demonstrates the simplest way to integrate Snack Money payments using axios with the x402 v2 payment client. Perfect for most web applications.

Overview

@x402/axios v2 wraps the popular axios HTTP client with automatic x402 payment negotiation. When the API returns 402 Payment Required, the client handles the payment flow automatically.

Features

  • Base (EVM) and Solana (SVM) network support
  • Automatic payment negotiation
  • Simple axios-based API
  • Type-safe TypeScript
  • Minimal setup

Prerequisites

  • Node.js 18+
  • USDC balance on Base or Solana network
  • EVM private key (for Base) or SVM private key (for Solana)

Installation

Quick Start

1. Set Up Environment

Create a .env file:
Important: Use your own X (Twitter) account as the receiver to test the integration safely.

2. Implement Base (EVM) Payment

Create base-send.ts:

3. Implement Solana (SVM) Payment

Create solana-send.ts:

4. Run the Example

For Base network:
For Solana network:

Expected Output

How It Works

  1. Create Signer: Generate account from your private key (EVM or SVM)
  2. Create x402 Client: Initialize the x402 client
  3. Register Scheme: Register the appropriate payment scheme (EVM or SVM)
  4. Wrap Axios: Add x402 payment wrapper
  5. Make Request: POST to /payments/x/pay
  6. Auto Payment: Client handles 402 response automatically
  7. Retry: Request retries with payment proof
  8. Success: Receive confirmation and receipt

Supported Endpoints

X (Twitter) Payments

Farcaster Payments

GitHub Payments

Configuration Options

Custom Axios Instance

Request Options

Error Handling

Common Errors

Insufficient USDC Balance
Invalid Private Key
User Not Found

Testing Tips

  1. Start small: Use 0.01 USDC for initial tests
  2. Test on yourself: Send to your own X account
  3. Check balance: Verify USDC balance before sending
  4. Save receipts: Keep receipt URLs for records

Full Example Repository

View the complete example with configuration files: View on GitHub → The repository includes:
  • Complete TypeScript implementation
  • Environment configuration template
  • package.json with all dependencies
  • Detailed README

Next Steps

Dependencies

Learn More