npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@asterpay-io/x402

v1.0.0

Published

x402 Protocol SDK - AI Agent Payment Infrastructure for Europe

Readme

@asterpay/x402

The European x402 Leader - AI Agent Payment Infrastructure

x402 Protocol SDK for autonomous AI agent payments. MiCA-compliant, GDPR-ready, with EUR off-ramp support.

Features

  • 🤖 AI Agent Wallet - Autonomous wallets with spending controls
  • x402 Protocol - HTTP 402 Payment Required handling
  • 🔒 Spending Limits - Per-transaction, hourly, daily, monthly limits
  • 🛡️ Service Allowlists - Control which services can be paid
  • 🔗 LangChain Integration - Ready-to-use tools for AI agents
  • 🇪🇺 EU Compliant - MiCA-ready, GDPR compliant

Installation

npm install @asterpay/x402
# or
yarn add @asterpay/x402
# or
pnpm add @asterpay/x402

Quick Start

Basic Usage

import { createX402Client, createAgentWallet } from '@asterpay/x402';

// Create a wallet for your AI agent
const wallet = createAgentWallet({
  name: 'Research Agent',
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  network: 'base',
  spendingLimits: {
    perTransaction: 1.00,  // Max $1 per transaction
    daily: 10.00,          // Max $10 per day
    monthly: 100.00        // Max $100 per month
  },
  allowedServices: [
    'api.openai.com',
    'api.anthropic.com',
    'api.coingecko.com'
  ]
});

// Create x402 client
const client = createX402Client({
  wallet: {
    name: 'Research Agent',
    privateKey: process.env.AGENT_PRIVATE_KEY!,
    network: 'base',
    spendingLimits: { daily: 10.00 }
  },
  autoPayEnabled: true,
  debug: true
});

// Make requests - 402 responses are handled automatically
const response = await client.fetch('https://api.paid-service.com/premium-data');
const data = await response.json();

LangChain Integration

import { setupAsterPayForLangChain } from '@asterpay/x402/langchain';
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';

// Quick setup
const { tools, wallet, client } = setupAsterPayForLangChain({
  privateKey: process.env.AGENT_KEY!,
  network: 'base',
  dailyLimit: 10,
  monthlyLimit: 100
});

// Available tools:
// - asterpay_check_balance: Check wallet balance
// - asterpay_check_spending: Check spending limits
// - asterpay_paid_fetch: Fetch URLs with automatic payment
// - asterpay_get_transactions: Get transaction history

const llm = new ChatOpenAI({ model: 'gpt-4' });
const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });

// Agent can now make paid API calls autonomously
const result = await executor.invoke({
  input: 'Fetch the latest Bitcoin price from the premium API'
});

Agent Wallet Features

import { createAgentWallet } from '@asterpay/x402';

const wallet = createAgentWallet({
  name: 'Trading Bot',
  privateKey: process.env.BOT_KEY!,
  network: 'base',
  spendingLimits: {
    perTransaction: 0.50,
    hourly: 5.00,
    daily: 20.00,
    monthly: 200.00
  },
  allowedServices: ['api.coingecko.com', 'api.dexscreener.com'],
  blockedServices: ['gambling.com'],
  autoPayEnabled: true,
  maxAutoPayAmount: 0.10
});

// Check balance
const balance = await wallet.getBalance();
console.log(`Balance: $${balance}`);

// Check if payment would be allowed
const check = wallet.canPay({ 
  amount: 0.05, 
  service: 'api.coingecko.com' 
});
console.log(check); // { allowed: true }

// Get spending summary
const spending = wallet.getSpendingSummary();
console.log(spending.daily); // { spent: 2.50, limit: 20, remaining: 17.50 }

// Get transaction history
const txs = wallet.getTransactions({ limit: 10 });

Custom Approval Logic

const client = createX402Client({
  wallet: walletConfig,
  autoPayEnabled: true,
  onApproval: async (payment, context) => {
    // Custom logic before payment
    console.log(`Payment request from ${context.url}`);
    console.log(`Amount: ${payment.maxAmountRequired}`);
    
    // Return true to approve, false to reject
    const amountUsd = parseInt(payment.maxAmountRequired) / 1_000_000;
    return amountUsd < 1.00; // Only approve < $1
  },
  onTransaction: (tx) => {
    console.log(`Payment completed: ${tx.txHash}`);
    // Log to analytics, update UI, etc.
  },
  onError: (error) => {
    console.error('Payment error:', error);
    // Alert, retry logic, etc.
  }
});

Supported Networks

| Network | Chain ID | Status | |---------|----------|--------| | Base | 8453 | ✅ Mainnet | | Base Sepolia | 84532 | ✅ Testnet | | Polygon | 137 | ✅ Mainnet | | Polygon Amoy | 80002 | ✅ Testnet | | Arbitrum | 42161 | ✅ Mainnet | | Arbitrum Sepolia | 421614 | ✅ Testnet | | Ethereum | 1 | ✅ Mainnet | | Ethereum Sepolia | 11155111 | ✅ Testnet | | BNB Chain | 56 | ✅ Mainnet | | BNB Testnet | 97 | ✅ Testnet |

API Reference

createX402Client(options)

Creates an x402 client for handling HTTP 402 responses.

const client = createX402Client({
  wallet: AgentWalletConfig,
  autoPayEnabled?: boolean,    // Default: true
  onApproval?: PaymentApprovalCallback,
  onTransaction?: TransactionCallback,
  onError?: ErrorCallback,
  debug?: boolean              // Default: false
});

createAgentWallet(config)

Creates an AI agent wallet with spending controls.

const wallet = createAgentWallet({
  name: string,
  privateKey: string,
  network: SupportedNetwork,
  spendingLimits?: SpendingLimits,
  allowedServices?: string[],
  blockedServices?: string[],
  autoPayEnabled?: boolean,
  maxAutoPayAmount?: number
});

setupAsterPayForLangChain(config)

Quick setup for LangChain integration.

const { tools, wallet, client } = setupAsterPayForLangChain({
  privateKey: string,
  network?: string,
  name?: string,
  dailyLimit?: number,
  monthlyLimit?: number,
  perTransactionLimit?: number
});

Security Best Practices

  1. Never commit private keys - Use environment variables
  2. Set spending limits - Always configure limits for agent wallets
  3. Use allowlists - Restrict which services can receive payments
  4. Monitor transactions - Use onTransaction callback for logging
  5. Test on testnet first - Use Base Sepolia or Polygon Amoy
// ✅ Good: Environment variable
const wallet = createAgentWallet({
  privateKey: process.env.AGENT_PRIVATE_KEY!,
  ...
});

// ❌ Bad: Hardcoded key
const wallet = createAgentWallet({
  privateKey: '0x1234...', // NEVER DO THIS
  ...
});

EUR Off-Ramp (Coming Soon)

AsterPay is the only x402 facilitator with EUR off-ramp support:

// Coming in v1.1
import { createEurOffRamp } from '@asterpay/x402';

const offRamp = createEurOffRamp({
  apiKey: process.env.ASTERPAY_API_KEY!,
  iban: 'DE89370400440532013000'
});

// Automatically convert USDC to EUR
await offRamp.withdraw({
  amount: 100, // $100 USDC
  // Arrives in EUR via SEPA Instant
});

Support

  • 📧 Email: [email protected]
  • 📚 Docs: https://asterpay.io/docs
  • 💬 Telegram: https://t.me/asterpaycommunity
  • 🐦 Twitter: https://x.com/asterpayio

License

MIT © AsterPay