Snack Money Examples
33by snack-money
Snack Money API examples
Getting Started
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- Dependenciesbase-send.ts- Base network implementationsolana-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 templateREADME.md- Detailed instructionstsconfig.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/payorsnack-money.pay.twitter(A2A) - Farcaster:
/payments/farcaster/payorsnack-money.pay.farcaster(A2A) - GitHub:
/payments/github/payorsnack-money.pay.github(A2A) - Email:
/payments/email/payorsnack-money.pay.email(A2A) - Web Domain:
/payments/web/payorsnack-money.pay.web(A2A) - Instagram:
/payments/instagram/payorsnack-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
- Initial Request: Client makes API call to Snack Money
- 402 Response: Server returns payment requirements
- Payment Execution: Client executes on-chain payment
- Retry with Proof: Client retries request with payment proof
- Success: Server processes and returns success response
A2A Protocol Flow (with X402 Extension)
- Discovery: Client fetches agent card to discover capabilities
- Initial Request: Client sends JSON-RPC request with skill method
- Payment Requirements: Server returns taskId and payment requirements
- Payment Execution: Client executes on-chain payment
- Proof Submission: Client resubmits with taskId and payment proof
- Success: Server verifies and returns success response
Learn More
Support
For questions or issues:
- Visit snack.money
- Check the x402 specification