Skip to main content
This guide will help you send your first USDC payment to an X (Twitter) user using the simplest integration method: x402-axios.

Quick Example

Send USDC to any X user with just a few lines of code:
import axios from "axios";
import { withPaymentInterceptor } from "x402-axios";
import { privateKeyToAccount } from "viem/accounts";

// Create a signer from your private key
const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);

// Wrap axios with x402 payment interceptor
const api = withPaymentInterceptor(
  axios.create({ baseURL: "https://api.snack.money" }),
  account as never
);

// Send payment - x402 handles the payment flow automatically
const response = await api.post("/payments/x/pay", {
  amount: 0.01,
  currency: "USDC",
  receiver: "0xmesuthere",
  description: "Payment via x402"
});

console.log("Payment successful!", response.data);
// {
//   "code": 200,
//   "msg": "0.01 USDC sent successfully",
//   "data": {
//     "txn_id": "...",
//     "amount": 0.01,
//     "receipt": "https://snack.money/x/0xmesuthere?txn=..."
//   }
// }

How It Works

  1. Initial Request: Your app makes a payment request to Snack Money API
  2. 402 Response: API returns payment requirements (amount, recipient, chain)
  3. Auto Payment: x402-axios automatically executes the on-chain USDC transfer
  4. Retry with Proof: Request is retried with payment proof
  5. Success: API processes the payment and returns confirmation
Learn more about the x402 protocol.

Prerequisites

  • Node.js 18+
  • USDC balance on Base or Solana network
  • Private key for signing transactions

Installation

npm install axios x402-axios viem

Environment Setup

Create a .env file:
# For Base network (EVM)
EVM_PRIVATE_KEY=0x...

# For Solana network
SVM_PRIVATE_KEY=your_solana_private_key_base58

Supported Platforms

Send payments to users on:
  • X (Twitter) - /payments/x/pay
  • Farcaster - /payments/farcaster/pay
  • GitHub - /payments/github/pay

Next Steps