Skip to content

x402 payment protocol enabling AI agents to autonomously pay for APIs on Arbitrum. Features Sperax USDs stablecoin with auto-yield, payment channels for streaming micropayments, on-chain subscriptions, and a tool registry marketplace. Includes TypeScript SDK, Express middleware, and upgradeable smart contracts.

License

Notifications You must be signed in to change notification settings

nirholas/x402-stablecoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

X402 Payment Protocol with Sperax USDs

CI License: MIT Arbitrum

Revolutionary AI Agent Payment Infrastructure β€” HTTP 402 payments with yield-bearing USDs stablecoin on Arbitrum

🌟 Overview

X402 is a complete payment protocol implementation for AI agents, combining:

  • HTTP 402 - Payment Required standard for programmatic payments
  • Sperax USDs - Auto-yield stablecoin (8-25% APY) on Arbitrum
  • EIP-3009 - Gasless transfer authorization
  • Arbitrum L2 - Low-cost, fast transactions

πŸ’‘ Why X402 + USDs?

Feature Traditional Payments X402 + USDs
Fees 2-3% + fixed ~$0.001 gas
Settlement Days Seconds
Yield 0% 8-25% APY
AI Native ❌ βœ…
Gasless ❌ βœ… (EIP-3009)
Micropayments ❌ βœ…

πŸ“¦ Packages

Package Description
@x402/sdk Core SDK for X402 payments
@x402/cli Command-line interface
@x402/sperax-mcp MCP tools for AI agents
facilitator Payment verification server
yield-tracker USDs yield monitoring
contracts Solidity smart contracts

πŸš€ Quick Start

# Clone the repo
git clone https://github.com/nirholas/x402.git
cd x402

# Install dependencies
pnpm install

# Copy environment config
cp .env.example .env

# Start the facilitator server
pnpm facilitator:dev

# In another terminal, start yield tracker
pnpm yield-tracker

πŸ’° Make a Payment

Using the SDK

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

const client = new X402Client({
  network: 'arbitrum',
  facilitatorUrl: 'http://localhost:3002'
});

// Gasless payment with EIP-3009
const { txHash } = await client.pay({
  recipient: '0x...',
  amount: '1.50',  // $1.50 USDs
  token: 'USDs',
  gasless: true
});

console.log('Payment confirmed:', txHash);

Using MCP Tools (AI Agents)

{
  "tool": "x402_pay_with_usds",
  "arguments": {
    "recipient": "0x...",
    "amount": "1.50",
    "gasless": true,
    "memo": "API call payment"
  }
}

πŸ“ˆ Earn Yield on Payments Received

USDs automatically earns yield while sitting in your wallet:

import { SperaxClient } from '@x402/sdk';

const client = new SperaxClient({ network: 'arbitrum' });

// Check balance with yield earned
const { balance, yieldEarned, apy } = await client.getBalanceWithYield(address);

console.log(`Balance: $${balance}`);
console.log(`Yield Earned: $${yieldEarned}`);
console.log(`Current APY: ${apy}%`);

πŸ”§ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     HTTP 402      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AI Agent  β”‚ ◄─────────────────│   API Server    β”‚
β”‚   (Payer)   β”‚                   β”‚   (Paywall)     β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                   β”‚
       β”‚ EIP-3009 Auth                     β”‚ Verify
       β–Ό                                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 Facilitator Server                   β”‚
β”‚  β€’ Verify payment authorizations                     β”‚
β”‚  β€’ Submit transactions                               β”‚
β”‚  β€’ Track yields                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚
                       β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   Arbitrum Network      β”‚
         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
         β”‚  β”‚   USDs Token      β”‚  β”‚
         β”‚  β”‚   (Auto-Yield)    β”‚  β”‚
         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎯 Use Cases

1. AI Agent Tool Marketplace

Pay per API call with micropayments. No subscriptions, no minimums.

2. Content Monetization

Paywall articles, videos, or data with instant USDs payments.

3. Revenue Splitting

Automatic 80/20 split between developers and platforms.

4. Subscription Streaming

Pay-as-you-go subscriptions that auto-renew with yield earnings.

πŸ“‹ Contract Addresses

Arbitrum Mainnet

Contract Address
USDs Token 0xD74f5255D557944cf7Dd0E45FF521520002D5748
Sperax Vault 0x8EC1877698ACF262Fe8Ad8a295ad94D6ea258988
Revenue Splitter Deploy your own

Arbitrum Sepolia (Testnet)

Contract Address
USDs Token See deployment docs

πŸ› οΈ Development

# Run all tests
pnpm test

# Run contract tests
pnpm contracts:test

# Build all packages
pnpm build

# Format code
pnpm format

# Lint
pnpm lint

πŸ“š Documentation

🀝 Contributing

Contributions are welcome! Please read our Contributing Guide first.

πŸ“„ License

MIT License - see LICENSE for details.


Built with ❀️ for the AI economy

X402 is not affiliated with Sperax or Coinbase. USDs is a product of Sperax Foundation.

About

x402 payment protocol enabling AI agents to autonomously pay for APIs on Arbitrum. Features Sperax USDs stablecoin with auto-yield, payment channels for streaming micropayments, on-chain subscriptions, and a tool registry marketplace. Includes TypeScript SDK, Express middleware, and upgradeable smart contracts.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published