x402-pocket

Seamlessly integrate x402 payment protocol with n8n

Documentation

x402 Pocket Nodes for n8n

npm version
License: MIT

Seamlessly integrate x402 payment protocol with your n8n workflows. Make HTTP requests to x402-enabled APIs with automatic Solana/USDC payment handling.

šŸŽÆ What is x402?

x402 is an HTTP payment protocol that allows APIs to request micropayments for access. Think "HTTP 402 Payment Required" - but actually implemented with Solana blockchain payments.

šŸ“¦ Installation

Option 1: n8n Community Nodes (Recommended)

  1. Open n8n
  2. Go to Settings → Community Nodes
  3. Click Install a community node
  4. Enter: @blockchain-hq/n8n-nodes-x402-pocket
  5. Click Install

Option 2: Manual Installation

cd ~/.n8n/nodes
npm install @blockchain-hq/n8n-nodes-x402-pocket

Then restart n8n.

šŸš€ Quick Start

1. Setup Your Wallet (One-Time)

[Manual Trigger] → [x402 Wallet Manager]
  1. Add x402 Wallet Manager node
  2. Select Devnet (for testing)
  3. Run the workflow
  4. Copy the wallet address from output
  5. Fund it at https://spl-token-faucet.com/
  6. Re-run to verify funding

2. Make x402 Requests

[Trigger] → [x402 Wallet Manager] → [x402 Client] → [Process Data]
  1. Add x402 Wallet Manager and x402 Client nodes
  2. Connect them with a line
  3. Configure the Client with your API endpoint
  4. Run! Payments happen automatically

šŸ“– Full Setup Guide

🧩 Included Nodes

x402 Wallet Manager

Generate and manage a persistent Solana wallet for x402 payments.

Features:

  • āœ… Generate wallet once, use everywhere
  • āœ… Check balances (USDC & SOL)
  • āœ… Get funding instructions
  • āœ… Reset wallet if needed

Use Cases:

  • Initial wallet setup
  • Balance monitoring
  • Wallet management

x402 Client

Make HTTP requests to x402-enabled APIs with automatic payment.

Features:

  • āœ… Automatic x402 payment handling
  • āœ… Support for GET, POST, PUT, DELETE
  • āœ… Custom headers and request bodies
  • āœ… Configurable payment limits
  • āœ… Transaction details in output
  • āœ… Works with Wallet Manager or auto-generate mode

Use Cases:

  • Access paid AI APIs
  • Fetch paid data feeds
  • Call micropayment APIs
  • Monetize your own services

x402 Mock Server

Test x402 integration without real blockchain transactions.

Features:

  • āœ… Simulates x402 payment flow
  • āœ… No real money needed
  • āœ… Perfect for development

šŸ“‹ Examples

Simple Data Fetch

[Schedule: Every hour]
    ↓
[x402 Wallet Manager]
    ↓
[x402 Client]
  URL: https://api.weather-x402.com/forecast
  Method: POST
  Body: {"city": "San Francisco"}
    ↓
[Save to Database]

AI Text Generation

[Webhook Trigger]
    ↓
[x402 Wallet Manager]
    ↓
[x402 Client]
  URL: https://ai-api.example.com/generate
  Method: POST
  Body: {"prompt": "{{$json.query}}"}
    ↓
[Send Response]

Conditional Payments

[Manual Trigger]
    ↓
[x402 Wallet Manager]
    ↓
[IF: Balance > 5 USDC?]
    ↓ true
[x402 Client]
  URL: https://premium-api.com/data
    ↓
[Process Results]

šŸ”§ Configuration

Wallet Manager Settings

Setting Description Values
Network Blockchain network Devnet, Mainnet
Action What to do Get Info, Check Balance, Reset Wallet

Client Settings

Setting Description Default
Wallet Source Where to get wallet Wallet Manager (recommended)
Resource URL x402 API endpoint -
HTTP Method Request method POST
Request Body JSON payload {}
Auto-Pay Automatically pay if required true
Max Payment Safety limit (USDC) 1
Headers Custom HTTP headers -

šŸ”’ Security

  • šŸ” Wallets are stored in n8n's encrypted database
  • šŸ” Private keys never leave your n8n instance
  • šŸ” Use Devnet for testing (no real money)
  • šŸ” Set payment limits to avoid overspending
  • šŸ” Monitor balances regularly

🌐 Networks

Devnet (Testing)

Mainnet (Production)

  • Real money
  • Buy USDC on exchanges
  • Need SOL for transaction fees

šŸ› ļø Development

Build from Source

# Clone the repo
git clone https://github.com/blockchain-hq/x402-pocket-nodes
cd x402-pocket-nodes

# Install dependencies
pnpm install

# Build
pnpm run build

# Link to n8n (for development)
npm link
cd ~/.n8n/nodes
npm link @blockchain-hq/n8n-nodes-x402-pocket

Project Structure

src/
ā”œā”€ā”€ nodes/
│   ā”œā”€ā”€ X402Client/           # Client node
│   ā”œā”€ā”€ X402MockServer/       # Mock server node
│   └── X402WalletManager/    # Wallet manager node
ā”œā”€ā”€ utils/
│   ā”œā”€ā”€ solana.utils.ts       # Solana helpers
│   ā”œā”€ā”€ x402.client.ts        # x402 client logic
│   ā”œā”€ā”€ x402.server.ts        # x402 server logic
│   └── x402.types.ts         # Type definitions
└── index.ts                  # Entry point

šŸ“ TODO / Roadmap

  • Add support for more payment schemes (hashlock, invoice)
  • Support for other tokens (SOL, custom SPL tokens)
  • Wallet credential type for better security
  • Multi-wallet support
  • Payment history tracking
  • Balance alerts/notifications
  • Support for other blockchains (Ethereum, etc.)

šŸ¤ Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Write tests if applicable
  5. Submit a pull request

šŸ“„ License

MIT License - see LICENSE file

šŸ”— Links

šŸ’¬ Support

  • šŸ“– Check WALLET_SETUP.md for detailed setup guide
  • šŸ› Report bugs via GitHub Issues
  • šŸ’” Feature requests welcome!

šŸŽ‰ Credits

Built with ā¤ļø for the n8n and Solana communities.


Made with n8n šŸš€ Powered by Solana ⚔ Following x402 Protocol šŸ’³

Discussion