Skip to main content
This example demonstrates a minimal integration using x402 v2 with axios. Despite the name “fetch”, this example uses the @x402/axios package for consistency and simplicity. Perfect for Node.js applications with minimal setup.

Overview

@x402/axios v2 provides a minimal integration with automatic x402 payment handling, with support for both EVM and SVM networks.

Features

  • Base (EVM) and Solana (SVM) network support
  • Minimal setup - Quick integration
  • Minimal dependencies
  • Type-safe TypeScript
  • Simple pattern

Prerequisites

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

Installation

Quick Start

1. Set Up Environment

Create a .env file:

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

Network Support

Base (EVM)

Solana (SVM)

Switching Networks

Simply change the NETWORK environment variable:

Supported Platforms

Error Handling

Why x402-fetch?

Advantages

  • Minimal Dependencies: Uses native fetch
  • Multi-Chain: Supports Base and Solana
  • Lightweight: Small bundle size
  • Familiar API: Standard fetch interface

Best For

  • Node.js applications
  • Minimal dependency requirements
  • Multi-chain support needed
  • Backend services

Full Example Repository

View on GitHub → Includes:
  • Base and Solana implementations
  • Environment templates
  • Complete setup guide

Next Steps

Dependencies

Learn More