Menu

Explorer & Settings

Tempo Explorer Submit Project
Back to all projects

x402-sdk

by SagarKarmoker · Updated 5 months ago

402-as-a-Service SDK A production-grade TypeScript SDK for integrating x402 payments into your applications. Enable HTTP 402 Payment Required for your APIs with just a few lines of code.

In the AI payments ecosystem

x402-sdk is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on x402, x402-payment. It currently has 0 GitHub stars and 0 forks, and sits alongside related tools like X402-audio-to-audio, sample-agentcore-cloudfront-x402-payments, spritz, x402-facilitator, Vault-0, tdm-sdk.

README.md View on GitHub →

402-as-a-Service SDK

A production-grade TypeScript SDK for integrating x402 payments into your applications. Enable HTTP 402 Payment Required for your APIs with just a few lines of code.

Features

  • Middleware for Popular Frameworks: Express, Next.js, Hono, Fastify
  • Wallet Adapters: EVM (Base, Ethereum) and Solana support
  • Usage Metering: Track API usage and revenue
  • Revenue Dashboard: Built-in analytics dashboard
  • Retry-After-Payment: Automatic payment handling in clients
  • Type-Safe: Full TypeScript support
  • Production-Ready: Comprehensive error handling and validation

Quick Start

Server Setup (Express)

import express from 'express';
import { paymentMiddleware } from '@x402/server/express';
import { NetworkIdentifiers } from '@x402/core';

const app = express();

app.use(paymentMiddleware({
  payTo: '0xYourAddress',
  routes: {
    'GET /api/premium': {
      accepts: [{
        scheme: 'exact',
        price: '$0.01',
        network: NetworkIdentifiers.BASE_MAINNET,
        payTo: '0xYourAddress'
      }],
      description: 'Premium API access'
    }
  }
}));

app.get('/api/premium', (req, res) => {
  res.json({ data: 'premium content' });
});

Client Setup (Fetch)

import { createX402Fetch } from '@x402/client/fetch';
import { EVMWalletAdapter } from '@x402/wallet-adapters/evm';

const wallet = new EVMWalletAdapter({
  privateKey: process.env.PRIVATE_KEY,
  network: NetworkIdentifiers.BASE_MAINNET
});

const fetch = createX402Fetch({ wallet, autoPay: true });

// Automatically handles payments
const response = await fetch('https://api.example.com/premium');
const data = await response.json();

Packages

  • @x402/core - Core types, utilities, and facilitator client
  • @x402/server - Server middleware (Express, Next.js, Hono, Fastify)
  • @x402/client - Client SDK (Fetch, Axios)
  • @x402/wallet-adapters - Wallet adapters (EVM, Solana)
  • @x402/metering - Usage metering and analytics
  • @x402/dashboard - Revenue dashboard

Installation

# Install server packages
npm install @x402/core @x402/server

# Install client packages
npm install @x402/core @x402/client @x402/wallet-adapters

# Install metering and dashboard
npm install @x402/metering @x402/dashboard

Documentation

Examples

Supported Networks

EVM

  • Base Mainnet (eip155:8453)
  • Base Sepolia (eip155:84532)
  • Ethereum Mainnet (eip155:1)
  • Ethereum Sepolia (eip155:11155111)

Solana

  • Solana Mainnet (solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp)
  • Solana Devnet (solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1)

Architecture

┌─────────────────┐     402 Payment Required     ┌─────────────────┐
│   Client App    │◄────────────────────────────►│   Server API    │
│  (with wallet)  │   Payment Payload (X-Payment) │ (x402 middleware)│
└────────┬────────┘                             └────────┬────────┘
         │                                               │
         │         ┌──────────────────┐                  │
         └────────►│  Facilitator     │◄─────────────────┘
                   │  (x402.org)      │
                   │  - Verify        │
                   │  - Settle        │
                   └──────────────────┘

License

Apache-2.0

Support

All SDKs & Clients SDKs →