Skip to main content
This example demonstrates integration using thirdweb’s x402 payment wrapper API. Perfect for applications already using the thirdweb ecosystem.

Overview

Integrate Snack Money payments using thirdweb’s x402 fetch wrapper, which handles payment negotiation through thirdweb’s managed infrastructure.

Features

  • Base network support
  • Managed infrastructure - thirdweb handles x402 flow
  • x402 wrapper via API - Automatic payment negotiation
  • Server-side wallet - Secure key management
  • thirdweb ecosystem - Works with other thirdweb tools

Prerequisites

  • Node.js 18+
  • thirdweb account (Sign up)
  • thirdweb Secret Key
  • thirdweb server wallet with USDC balance on Base

Installation

Quick Start

1. Get thirdweb Credentials

  1. Visit thirdweb Dashboard
  2. Create a new project
  3. Get your Client ID and Secret Key
  4. Create a wallet and fund with USDC

2. Set Up Environment

Create a .env file:
Important: The WALLET_ADDRESS should be your thirdweb server wallet address that has USDC on Base network.

3. Implement Payment

Create base-send.ts:

4. Run the Example

Expected Output

How It Works

  1. Initialize thirdweb: Create client with API credentials
  2. Create Wallet: Load wallet from private key
  3. Convert Account: Convert to viem format for x402
  4. Wrap Axios: Add payment interceptor
  5. Send Payment: Make payment request

Why thirdweb?

Benefits

  • Managed Infrastructure: thirdweb handles blockchain complexity
  • Ecosystem Integration: Works with other thirdweb services
  • Developer Experience: Simple, consistent APIs
  • Multi-Chain Support: Easy to extend to other chains

Best For

  • Apps already using thirdweb
  • Need thirdweb ecosystem features
  • Want managed infrastructure
  • Building multi-chain apps

Supported Platforms

thirdweb Features

Using thirdweb Wallets

Smart Wallets

Error Handling

Full Example Repository

View on GitHub → Includes:
  • Complete implementation
  • thirdweb configuration
  • Environment setup
  • Detailed README

Next Steps

Dependencies

Learn More