AllScale x402 Charity

Micro-donations,
built into every payment.

Embed automatic charitable giving into any payment flow. No extra steps. No separate UI. Just part of the transaction.

Programmable Giving

Attach a cause to any event — a trade, an API call, a subscription. Donations happen in the background.

Powered by x402

Uses the x402 protocol for native HTTP stablecoin payments. USDC on Base — fast, cheap, and gas-efficient.

Open Source

MIT licensed. Add your charity to the registry. Integrate with Express, Next.js, or the CLI.


Get Started

Pick how you want to integrate — CLI, Express middleware, or Next.js middleware.

1. Install globally

$ npm install -g x402charity

2. Set your private key

$ x402charity config set-key YOUR_PRIVATE_KEY

3. Pick a network

$ x402charity config set-network base-sepolia

4. Donate

$ x402charity donate testing-charity 0.01

List available charities

$ x402charity list

1. Install

$ npm install @x402charity/express

2. Add middleware to your app

import express from 'express';
import { x402charity } from '@x402charity/express';

const app = express();

// Auto-donate 0.0001 USDC on every request to /api/trade
app.use('/api/trade', x402charity({
  privateKey: process.env.X402_PRIVATE_KEY,
  cause: 'testing-charity',
  amount: '0.0001',
  network: 'base-sepolia',
}));

app.post('/api/trade', (req, res) => {
  // your trade logic — donation happens automatically
  res.json({ ok: true });
});

app.listen(3000);

Options

x402charity({
  privateKey: '0x...',        // Wallet private key (required)
  cause: 'testing-charity',  // Charity ID (required)
  amount: '0.0001',          // USDC per event (default: 0.0001)
  network: 'base-sepolia',   // base or base-sepolia (default)
  silent: true,              // Suppress errors (default: true)
  shouldDonate: (req) => {   // Optional filter function
    return req.method === 'POST';
  },
});

1. Install

$ npm install @x402charity/next

2. Add to your middleware.ts

// middleware.ts
import { x402charity } from '@x402charity/next';

export default x402charity({
  privateKey: process.env.X402_PRIVATE_KEY,
  cause: 'testing-charity',
  amount: '0.0001',
  network: 'base-sepolia',
  matcher: '/api/*',       // Only donate on API routes
});

// Or match multiple paths:
// matcher: ['/api/trade', '/api/subscribe']

1. Install

$ npm install @x402charity/core

2. Use the client directly

import { X402CharityClient, listCharities } from '@x402charity/core';

// List available charities
const charities = listCharities();
console.log(charities);

// Create a client and donate
const client = new X402CharityClient({
  privateKey: process.env.X402_PRIVATE_KEY,
  network: 'base-sepolia',
});

const receipt = await client.donate('testing-charity', '0.01');
console.log('Tx hash:', receipt.txHash);

Build your own integration

The core library gives you X402CharityClient, listCharities(), findCharity(), and setCharities(). Use them to build donations into any workflow — cron jobs, webhooks, AI agents, or custom middleware.



Donation History

Live USDC donations to registered charities

Total Donated
Transactions
Unique Donors
Live from Blockscout
Loading donation history...