StackA2A
financetypescript

Snack Money Examples

33

by snack-money

Snack Money API examples

1 starsUpdated 2025-12-30
Quality Score33/100
Community
7
Freshness
68
Official
30
Skills
10
Protocol
40
🔒 Security
20

Getting Started

1Clone the repository
$ git clone https://github.com/snack-money/snack-money-examples
2Navigate to the project
$ cd snack-money-examples
3Install dependencies
$ npm install
4Run the agent
$ npm start

Or connect to the hosted endpoint: https://docs.snack.money

README

Snack Money API Examples

Examples demonstrating how to integrate with the Snack Money API using different x402 payment clients.

What is Snack Money?

Snack Money enables USDC payments to users across multiple platforms (X/Twitter, Farcaster, GitHub, Email, Domains) using the x402 payment protocol.

Support Matrix

Library Base Solana Wallet Type Key Features
a2a Private Key A2A protocol, agent-to-agent, JSON-RPC 2.0, X402 extension
axios Private Key Simple integration, interceptor pattern
cdp-sdk Server (CDP MPC) No private key management, enterprise security
fetch Private Key Minimal dependencies, native fetch wrapper
crossmint - Server (Smart Contract) API-based signing, smart contract wallets
thirdweb - Server (Managed) Managed infrastructure, no private key in code

Summary:

  • Total implementations: 6
  • Base support: 6/6 (100%)
  • Solana support: 4/6 (67%)
  • Private key wallets: 3 (a2a, axios, fetch)
  • Server wallets: 3 (cdp-sdk, crossmint, thirdweb)

Wallet Types:

  • Private Key: Direct private key signing
  • Server (CDP MPC): Coinbase Developer Platform with MPC technology
  • Server (Smart Contract): Crossmint smart contract wallet with API signing
  • Server (Managed): Thirdweb managed payment infrastructure

Available Examples

Each example demonstrates sending USDC to users across multiple platforms via configurable environment variables.

1. a2a - A2A Protocol

Agent-to-Agent protocol with X402 extension

  • ✅ A2A protocol with JSON-RPC 2.0
  • ✅ X402 extension for payments
  • ✅ Agent card discovery
  • ✅ Base network support
  • ✅ Solana network support
  • ✅ Task-based async payment flow
  • ✅ Support for 6 platforms (Twitter, Farcaster, GitHub, Email, Web, Instagram)
  • ✅ Type-safe TypeScript

2. axios - x402-axios

Axios HTTP client with x402 payment interceptor

  • ✅ Base network support
  • ✅ Solana network support
  • ✅ Payment interceptor pattern
  • ✅ Simple integration
  • ✅ Type-safe TypeScript

2. cdp-sdk - Coinbase CDP SDK

Server-side wallet management with MPC security

  • ✅ Base network support
  • ✅ Solana network support
  • ✅ Create Solana accounts
  • ✅ No private key management
  • ✅ Enterprise-grade security
  • ✅ Perfect for backend apps

3. cdp-sdk - Coinbase CDP SDK

Server-side wallet management with MPC security

  • ✅ Base network support
  • ✅ Solana network support
  • ✅ Create Solana accounts
  • ✅ No private key management
  • ✅ Enterprise-grade security
  • ✅ Perfect for backend apps

4. fetch - x402-fetch

Native fetch API wrapper

  • ✅ Base network support
  • ✅ Solana network support
  • ✅ Minimal dependencies
  • ✅ Simple wrapper pattern
  • ✅ TypeScript support

5. thirdweb - thirdweb

Managed infrastructure with thirdweb API

  • ✅ Base network support
  • ✅ Create Solana wallets
  • ✅ Managed payment infrastructure
  • ✅ No private key in code

6. crossmint - Crossmint Smart Wallets

Smart contract wallet with x402 protocol

  • ✅ Base network support
  • ✅ Smart wallet infrastructure
  • ✅ Account abstraction
  • ✅ API-based signing

Quick Start

Each example has its own directory with:

  • package.json - Dependencies
  • base-send.ts - Base network implementation
  • solana-send.ts - Solana network implementation (where supported)
  • agent-card-fetch.ts - Agent discovery (A2A only)
  • create-*-wallet.ts - Wallet creation utilities (where available)
  • .env.example - Configuration template
  • README.md - Detailed instructions
  • tsconfig.json - TypeScript config

To run any example:

cd <example-directory>
yarn install
cp .env.example .env
# Edit .env with your credentials and receiver username
yarn base       # For Base network
yarn solana     # For Solana network (where supported)
yarn agent-card # View agent capabilities (A2A only)

All examples require setting:

  • RECEIVER: X (Twitter) username to send payment to (without @) - use your own X account for testing
  • AMOUNT: Amount to send in USDC (default: 0.01)

Features

All implementations support:

  • ✓ USDC payments to users across multiple platforms
  • ✓ x402 payment protocol (or A2A with X402 extension)
  • ✓ Production Snack Money API
  • ✓ Transaction receipts and proof
  • ✓ Type-safe TypeScript

Network Coverage:

  • 6/6 implementations support Base (100%)
  • 4/6 implementations support Solana (67%)

Wallet Options:

  • 3 implementations use private keys directly (a2a, axios, fetch)
  • 3 implementations use server-side wallet management (cdp-sdk, crossmint, thirdweb)

Testing

Start with a small amount (0.01 USDC = 1¢) to test the integration before scaling up.

Supported Networks

  • Base (Mainnet)
  • Solana (Mainnet)

Supported Payment Destinations

  • X (Twitter): /payments/x/pay or snack-money.pay.twitter (A2A)
  • Farcaster: /payments/farcaster/pay or snack-money.pay.farcaster (A2A)
  • GitHub: /payments/github/pay or snack-money.pay.github (A2A)
  • Email: /payments/email/pay or snack-money.pay.email (A2A)
  • Web Domain: /payments/web/pay or snack-money.pay.web (A2A)
  • Instagram: /payments/instagram/pay or snack-money.pay.instagram (A2A)

API Endpoints

All examples use the production API:

X402 Protocol:

https://api.snack.money

A2A Protocol:

Agent Card: https://api.snack.money/a2a/.well-known/agent-card
JSON-RPC: https://api.snack.money/a2a

Example Request

{
  amount: 0.01,
  currency: "USDC",
  receiver: "username",
  description: "Payment via x402"
}

Example Response

{
  "code": 200,
  "msg": "0.01 USDC sent successfully",
  "data": {
    "txn_id": "...",
    "amount": 0.01,
    "receipt": "https://snack.money/x/username?txn=..."
  }
}

How it Works

X402 Protocol Flow

  1. Initial Request: Client makes API call to Snack Money
  2. 402 Response: Server returns payment requirements
  3. Payment Execution: Client executes on-chain payment
  4. Retry with Proof: Client retries request with payment proof
  5. Success: Server processes and returns success response

A2A Protocol Flow (with X402 Extension)

  1. Discovery: Client fetches agent card to discover capabilities
  2. Initial Request: Client sends JSON-RPC request with skill method
  3. Payment Requirements: Server returns taskId and payment requirements
  4. Payment Execution: Client executes on-chain payment
  5. Proof Submission: Client resubmits with taskId and payment proof
  6. Success: Server verifies and returns success response

Learn More

Support

For questions or issues:

Capabilities

StreamingPush NotificationsMulti-TurnAuth: none
x402x402-payment
View on GitHub