Skip to content

xpaysh/x402-local

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

x402-local

⚑ Stop waiting for testnet faucets. Start building x402 agents in 30 seconds.

npm version License: MIT Downloads

πŸš€ Quick Start

npx @xpay/x402-local

That's it! In 30 seconds you get:

  • βœ… Local facilitator running on :3402
  • βœ… 5 funded test wallets created
  • βœ… Instant payment confirmations
  • βœ… Ready for x402 development!

No testnet setup. No faucet waiting. No slow confirmations.

πŸ“¦ What You Get

πŸ—οΈ Local Facilitator

  • Full x402 protocol simulation on localhost:3402
  • /verify and /settle endpoints that work like mainnet
  • Instant confirmations (or add realistic delays for testing)

πŸ’° Pre-funded Test Wallets

  • 5 wallets with different USDC balances (1000-3000)
  • No faucet needed - ready to use immediately
  • Private keys provided for testing agents

⚑ Zero-Friction Development

  • Works with any x402 client library
  • Perfect for agent development and API testing
  • Docker support for CI/CD pipelines

🎯 Perfect For

  • AI Agent Development - Test payment flows without mainnet complexity
  • x402 API Development - Build and test protected endpoints locally
  • Integration Testing - Verify payment logic before production
  • Learning x402 - Understand the protocol without crypto friction

πŸ“– Usage

Basic Commands

# Start with defaults (port 3402, 5 wallets, instant payments)
npx @xpay/x402-local

# Custom configuration
npx @xpay/x402-local start --port 3403 --wallets 10

# Add realistic delays for testing
npx @xpay/x402-local start --delay 1000

# Check status
npx @xpay/x402-local status

# Manage wallets
npx @xpay/x402-local wallets
npx @xpay/x402-local wallets --create --fund 2000

Example: Testing x402 API

  1. Start the local environment:

    npx @xpay/x402-local
  2. Test the facilitator endpoints:

    # Health check
    curl http://localhost:3402/health
    
    # Get payment requirements
    curl http://localhost:3402/payment-requirements
  3. Build your x402-protected API using the local facilitator:

    // Your API can now use http://localhost:3402 as the facilitator
    const facilitatorUrl = 'http://localhost:3402';

πŸ”§ API Reference

Facilitator Endpoints

The local facilitator simulates a production x402 facilitator:

Endpoint Method Description
/health GET Health check and configuration
/verify POST Verify x402 payment
/settle POST Settle verified payment
/payment-requirements GET Get payment requirements for testing
/payments GET List recent payments (debug)

Test Wallets

Default wallets created with x402-local start:

Wallet 1: 1000 USDC
Wallet 2: 1500 USDC  
Wallet 3: 2000 USDC
Wallet 4: 2500 USDC
Wallet 5: 3000 USDC

Each wallet includes:

  • Ethereum-style address (0x...)
  • Private key for signing transactions
  • Pre-funded USDC balance

πŸ€– Agent Development

Perfect for building AI agents that make x402 payments:

import { X402Client } from '@xpay/x402-sdk';

const client = new X402Client({
  facilitatorUrl: 'http://localhost:3402',
  privateKey: 'your-test-wallet-key'
});

// Your agent can now make payments to x402-protected APIs
const response = await client.request('http://your-api.com/protected-endpoint');

πŸ‘‰ Next: Build complete agents with x402-agent-kit

🐳 Docker Support

Use in CI/CD or containerized development:

# Pull the image
docker pull xpay/x402-local

# Run with default settings
docker run -p 3402:3402 xpay/x402-local

# Custom configuration
docker run -p 3403:3403 xpay/x402-local --port 3403 --wallets 10

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Your Agent    β”‚    β”‚   x402-local     β”‚    β”‚  Your x402 API  β”‚
β”‚                 β”‚    β”‚   Facilitator    β”‚    β”‚                 β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ X402 Client β”‚ │───▢│ β”‚ /verify      β”‚ │◀───│ β”‚ Middleware  β”‚ β”‚
β”‚ β”‚             β”‚ β”‚    β”‚ β”‚ /settle      β”‚ β”‚    β”‚ β”‚             β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”‚
         └──────────────▢│   Test Wallets   β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ (Pre-funded USDC)β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”— xPay x402 Ecosystem

x402-local is part of the complete xPay x402 developer toolkit:

🚧 Roadmap

  • Core CLI with local facilitator
  • Pre-funded test wallets
  • Instant payment simulation
  • Browser extension for testing
  • Docker image for CI/CD
  • WebSocket support for real-time updates
  • Payment flow visualization
  • Integration with popular testing frameworks

🀝 Contributing

We love contributions! Please see our Contributing Guide.

Quick ways to help:

  • πŸ› Report bugs or request features
  • πŸ“ Improve documentation
  • πŸ§ͺ Add test cases
  • πŸ’‘ Suggest new features

πŸ“„ License

MIT License - see LICENSE for details.

πŸ†˜ Support


πŸš€ Built by xPay - Helping the agentic community get paid and pay safely
If this tool helped you build with x402, please ⭐ star the repo!

Explore x402 Resources β€’ Build AI Agents β€’ Learn x402 Protocol

About

x402 development without the testnet hassle - instant local environment

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors