Skip to content

Open-source x402 payment processor for AI agents. Sub-400ms settlement on Solana + 7 EVM chains. Let LLMs pay for APIs programmatically with USDC. npm: nory-x402

License

Notifications You must be signed in to change notification settings

TheMemeBanker/x402-pay

Repository files navigation

Nory - x402 Payment Protocol Implementation

The fastest, most efficient x402 payment processor for AI agents and micropayments.

What is x402?

x402 is an open HTTP payment protocol that enables:

  • AI agents to pay for API access programmatically
  • Micropayments without traditional payment rails
  • Multi-chain support (Solana, Base, Polygon, Arbitrum, Optimism, Avalanche, and more)

When a client requests a paid resource, the server responds with HTTP 402 and payment requirements. The client pays and retries with proof of payment.

Features

  • Multi-chain: Solana + 7 EVM chains supported
  • 0.1% fees: Lowest in the industry
  • Sub-second verification: Optimized for speed
  • Echo mode: Test payments with real refunds
  • Enterprise security: API keys, HMAC signing, rate limiting
  • Observability: Structured logging, metrics, health checks

Quick Start

Installation

npm install @nory/x402-client

Client Usage

import { NoryClient } from '@nory/x402-client';

const client = new NoryClient({
  baseUrl: 'https://noryx402.com',
  apiKey: 'your_api_key', // optional
});

// Make a payment
const result = await client.pay({
  resource: 'https://api.example.com/premium-endpoint',
  network: 'solana-mainnet',
  amount: '1000000', // 1 USDC (6 decimals)
  payTo: 'merchant_wallet_address',
});

Server Integration

Add x402 payment requirements to any endpoint:

// Return 402 with payment requirements
return new Response(null, {
  status: 402,
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    x402Version: 2,
    accepts: [{
      network: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
      amount: '1000000',
      currency: 'USDC',
      payTo: 'YOUR_WALLET_ADDRESS',
    }],
    resource: request.url,
  }),
});

API Endpoints

Endpoint Description
POST /api/x402/verify Verify a payment before settlement
POST /api/x402/settle Settle a verified payment on-chain
GET /api/x402/requirements Get payment requirements for a resource
GET /api/x402/transactions/{id} Look up transaction status
GET /api/x402/health Service health check
GET /api/x402/metrics Performance metrics

Supported Networks

Network Chain ID Type
Solana Mainnet solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp Solana
Solana Devnet solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1 Solana
Base eip155:8453 EVM
Polygon eip155:137 EVM
Arbitrum eip155:42161 EVM
Optimism eip155:10 EVM
Avalanche eip155:43114 EVM
Sei eip155:1329 EVM
IoTeX eip155:4689 EVM

Self-Hosting

Prerequisites

  • Node.js 18+
  • PostgreSQL database
  • Solana/EVM wallet for receiving payments

Setup

  1. Clone the repository:
git clone https://github.com/TheMemeBanker/x402-pay.git
cd x402-pay
  1. Install dependencies:
npm install
  1. Configure environment:
cp .env.example .env
# Edit .env with your configuration
  1. Initialize database:
npx prisma db push
  1. Run development server:
npm run dev

Environment Variables

See .env.example for all configuration options. Key variables:

  • MERCHANT_WALLET - Your wallet address for receiving payments
  • DATABASE_URL - PostgreSQL connection string
  • NORY_API_KEY - Master API key for authentication
  • REFUND_WALLET_SECRET_KEY - (Optional) For Echo mode refunds

Security

  • API key authentication on all sensitive endpoints
  • HMAC request signing for webhook verification
  • Rate limiting per IP and API key
  • No secrets stored in code or git history

Documentation

Full documentation at noryx402.com/docs

License

MIT License - see LICENSE

Contributing

Contributions welcome! Please read our contributing guidelines before submitting PRs.

Links

About

Open-source x402 payment processor for AI agents. Sub-400ms settlement on Solana + 7 EVM chains. Let LLMs pay for APIs programmatically with USDC. npm: nory-x402

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published