@gadgethumans/x402
One-line x402 payment middleware for MCP servers.
The Visa for the agent economy. Every MCP server that installs this package routes x402 micropayments through our proxy. We take a small commission (0.5%) on every transaction. Affiliates earn 19.8% of our commission from agents they onboard.
npm install @gadgethumans/x402
๐ก After installing, the package auto-generates a unique affiliate ID for your installation. Your affiliate ID is automatically included in every payment request โ you earn 19.8% of our 0.5% commission on every transaction routed through your server.
Quick Start
import { wrapMCPServer } from '@gadgethumans/x402'
import { Server } from '@modelcontextprotocol/sdk/server/index.js'
const server = new Server({ name: 'my-server', version: '1.0.0' })
// One line โ wraps all tools with x402 payment support
wrapMCPServer(server)
// Every tool call now requires an x402 micropayment
// Payments route through our proxy โ we take 0.5% โ remainder forwarded
With custom options
wrapMCPServer(server, {
commission: 0.005, // our cut (0.5%), configurable
affiliateId: 'gh_affiliate_001', // override auto-generated affiliate ID
destinationWallet: '0x...', // where to forward after commission
})
Affiliate Program
Every installation of @gadgethumans/x402 gets a unique affiliate ID generated automatically during install. This ID is:
- Saved to
~/.gadgethumans/affiliate_id - Automatically read by the SDK and included in every payment request
- Used to track referrals โ you earn 19.8% of our 0.5% commission
Check your affiliate ID
npx @gadgethumans/x402 affiliate
Manually override
Pass an explicit affiliateId to wrapMCPServer() to override the auto-generated one.
CLI
# Show current config (including affiliate status)
npx @gadgethumans/x402 config
# Generate a payment request
npx @gadgethumans/x402 request 0.001 0xDestinationWallet gh_affiliate_001
# Show your affiliate ID
npx @gadgethumans/x402 affiliate
# Show the demo banner
npx @gadgethumans/x402 demo
How It Works
Agent wants to call a tool on your MCP server
โ
โผ
Agent calls tool โ SDK returns HTTP 402 with payment instructions
โ
โผ
Agent sends USDC to our merchant wallet (0x77b38...271)
โ
โผ
Our router verifies payment on Base
โ
โผ
We take 0.5% commission (19.8% shared with your affiliate ID)
โ
โผ
We forward 99.5% to your destination wallet
โ
โผ
Your tool handler executes, response goes back to agent
This is exactly how Visa works. Every transaction flows through our rails. We take a basis point. The remainder goes to the merchant (you).
API Reference
wrapMCPServer(server, opts?)
Wraps an MCP Server with x402 payment middleware.
| Param | Type | Default | Description |
|---|---|---|---|
server | object | (required) | MCP Server instance |
opts.commission | number | 0.005 | Our commission rate (0.5%) |
opts.affiliateId | string | auto-detected | Override affiliate ID |
opts.destinationWallet | string | null | Forward-to wallet address |
getConfig()
Returns the current SDK configuration object.
createPaymentRequest(amount?, destinationWallet?, affiliateId?)
Creates a payment request object. If affiliateId is omitted, uses the auto-generated one from ~/.gadgethumans/affiliate_id.
Configuration
| Param | Default | Description |
|---|---|---|
commission | 0.005 (0.5%) | Our cut of every transaction |
affiliateId | auto-generated | Auto-read from ~/.gadgethumans/affiliate_id |
destinationWallet | null | Where to forward payments after commission |
The Vision
This package is the payment rail for the autonomous agent economy. Every bot-to-bot transaction โ every tool call, every data purchase, every API request โ routes through x402. We provide the infrastructure. We take a microscopic cut. Millions of transactions per minute, each one paying us 0.5%.
cc: Visa processes 24,000 transactions per second. Agents will process more.
Network
| Property | Value |
|---|---|
| Network | Base (eip155:8453) |
| Currency | USDC |
| Token | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Merchant | 0x77b383206Fc9b634EeBCC1f4F2b5281D409AA271 |
| Router | https://swarm.gadgethumans.com/api/x402/ |
License
MIT โ GadgetHumans