Skip to main content
Explore different ways to integrate Snack Money’s x402 v2 payment API into your application. Each example demonstrates a complete implementation with a different SDK or infrastructure provider.

Available Examples

A2A Protocol

Agent-to-Agent protocol implementation with X402 extension.
  • Best for: AI agents and autonomous systems
  • Networks: Base (EVM), Solana (SVM)
  • Complexity: Simple
  • Features: Agent discovery, JSON-RPC 2.0, async payments
// Discover agent capabilities
GET https://api.snack.money/a2a/.well-known/agent-card

// Send payment via JSON-RPC
POST https://api.snack.money/a2a
{
  "jsonrpc": "2.0",
  "method": "snack-money.pay.twitter",
  "params": {
    "receiver": "username",
    "amount": 0.01
  }
}
View full example →

x402-axios (v2)

The simplest integration using axios with x402 v2 payment client.
  • Best for: Most web applications
  • Networks: Base (EVM), Solana (SVM)
  • Complexity: Simple
  • Dependencies: Minimal
import { x402Client, wrapAxiosWithPayment } from "@x402/axios";
import { registerExactEvmScheme } from "@x402/evm/exact/client";

const client = new x402Client();
registerExactEvmScheme(client, { signer: account });

const api = wrapAxiosWithPayment(
  axios.create({ baseURL: "https://api.snack.money" }),
  client
);

await api.post("/payments/x/pay", {
  amount: 0.01,
  currency: "USDC",
  receiver: "username"
});
View full example →

Coinbase CDP SDK

Server-side wallet management with MPC security.
  • Best for: Backend applications, enterprises
  • Networks: Base (EVM), Solana (SVM)
  • Complexity: Moderate
  • Key management: MPC-based, no private keys needed
const privateKey = await cdpClient.evm.exportAccount({ address: walletAddress });
const account = privateKeyToAccount(`0x${privateKey}`);

const client = new x402Client();
registerExactEvmScheme(client, { signer: account });

const api = wrapAxiosWithPayment(
  axios.create({ baseURL: "https://api.snack.money" }),
  client
);
View full example →

x402-fetch (v2)

Minimal integration using x402 v2 with axios under the hood.
  • Best for: Node.js apps, minimal footprint
  • Networks: Base (EVM), Solana (SVM)
  • Complexity: Simple
  • Dependencies: Minimal
import { x402Client, wrapAxiosWithPayment } from "@x402/axios";
import { registerExactEvmScheme } from "@x402/evm/exact/client";

const client = new x402Client();
registerExactEvmScheme(client, { signer: account });

const api = wrapAxiosWithPayment(
  axios.create({ baseURL: "https://api.snack.money" }),
  client
);
View full example →

thirdweb

Managed infrastructure with thirdweb’s payment API.
  • Best for: Apps using thirdweb ecosystem
  • Network: Base (EVM)
  • Complexity: Moderate
  • Key management: Managed by thirdweb
const wallet = new PrivateKeyWallet({
  client,
  privateKey: process.env.THIRDWEB_PRIVATE_KEY
});

// Use with x402 wrapper
View full example →

Crossmint Smart Wallets

Smart contract wallets with account abstraction.
  • Best for: Apps needing smart wallet features
  • Network: Base (EVM)
  • Complexity: Moderate
  • Features: Account abstraction, smart wallets
const wallet = CrossmintSmartWallet.build({
  config: { chain: "base" },
  signer: { type: "DEVELOPER_CONTROLLED" }
});

// Use with viem-compatible interface
View full example →

Comparison Matrix

ExampleNetwork(s)Private KeysComplexityBest For
A2ABase, SolanaDirect⭐ SimpleAI agents
axiosBase, SolanaDirect⭐ SimpleMost apps
CDP SDKBase, SolanaMPC managed⭐⭐ ModerateEnterprises
fetchBase, SolanaDirect⭐ SimpleNode.js apps
thirdwebBaseManaged⭐⭐ Moderatethirdweb users
CrossmintBaseSmart wallet⭐⭐ ModerateSmart wallets

Quick Start

Each example follows the same structure:
  1. Clone or copy the example code
  2. Install dependencies: npm install
  3. Configure environment: Copy .env.example to .env
  4. Add credentials: Private key and receiver username
  5. Run: npm run dev

Common Prerequisites

All examples require:
  • Node.js 18+
  • USDC balance on the target network
  • Receiver username: Use your own X account for testing

Supported Platforms

All examples support sending payments to:
  • X (Twitter) - /payments/x/pay
  • Farcaster - /payments/farcaster/pay
  • GitHub - /payments/github/pay

Network Support

NetworkaxiosCDP SDKfetchthirdwebCrossmint
Base
Solana

Choosing the Right Example

Use A2A if you’re:

  • Building AI agents or autonomous systems
  • Need agent discovery capabilities
  • Want JSON-RPC based communication
  • Implementing agent-to-agent payments

Use axios if you want:

  • Simplest integration
  • Familiar HTTP client
  • Minimal setup
  • Both Base and Solana support

Use CDP SDK if you want:

  • Enterprise-grade security
  • No direct private key management
  • Server-side wallets
  • Both Base and Solana support

Use fetch if you want:

  • Minimal dependencies
  • Simple integration
  • Both Base and Solana support

Use thirdweb if you’re:

  • Already using thirdweb
  • Building on their infrastructure
  • Need their ecosystem tools

Use Crossmint if you need:

  • Smart contract wallets
  • Account abstraction
  • Advanced wallet features

Integration Steps

1. Choose Your Example

Pick the example that matches your stack and requirements.

2. Set Up Environment

All examples use environment variables for configuration:
# For EVM networks (Base)
EVM_PRIVATE_KEY=0x...
RECEIVER=your_x_username
AMOUNT=0.01

# For Solana network (SVM)
SVM_PRIVATE_KEY=base58_key...

# Additional keys for specific examples
ANTHROPIC_API_KEY=sk-ant-...  # For AI features
CDP_API_KEY_ID=...            # For CDP SDK
THIRDWEB_SECRET_KEY=...       # For thirdweb
CROSSMINT_API_KEY=...         # For Crossmint

3. Install Dependencies

cd examples/<example-name>
npm install

4. Run the Example

npm run dev

Testing Tips

  1. Start small: Use 0.01 USDC (1 cent) for initial tests
  2. Test on yourself: Send to your own X account
  3. Check balance: Ensure sufficient USDC + gas fees
  4. Verify receipt: Click the receipt URL to confirm payment

Example Output

All examples produce similar output:
🚀 Starting Snack Money payment example

✅ Signer/wallet created
💸 Sending 0.01 USDC to @username on X...

✅ Payment successful!

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

Source Code

All example source code is available on GitHub: View examples repository → Each example includes:
  • Complete TypeScript implementation
  • Environment configuration
  • README with setup instructions
  • package.json with dependencies

Next Steps

  1. Choose an example that fits your needs
  2. Follow the guide for that specific example
  3. Integrate into your application
  4. Refer to API docs for advanced usage

Additional Resources

Getting Help

  • GitHub Issues: Report bugs or request features
  • Documentation: Comprehensive guides for each example
  • API Support: Contact via snack.money