Skip to content
Back to skills

X402 Payments

ASecurity

Agent-to-agent payments via HTTP 402 + on-chain escrow. Let agents pay each other for API calls, services, and data.

  • 57 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added May 31, 2026
developmenttypescriptrustgobashgitapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned May 31, 2026

npx -y skills add diegosouzapw/awesome-omni-skill --skill x402-payments --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of X402 Payments?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for X402 Payments
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/diegosouzapw-x402-payments/badge)](https://www.skillsdirectory.com/skills/diegosouzapw-x402-payments)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: x402-payments
version: 1.0.0
description: Agent-to-agent payments via HTTP 402 + on-chain escrow. Let agents pay each other for API calls, services, and data.
homepage: https://github.com/QUSD-ai/x402-payments
metadata:
  emoji: "πŸ’°"
  category: payments
  tags: ["x402", "payments", "escrow", "a2a", "defi"]
---

# X402 Agent Payments

Let your agent pay (and get paid by) other agents. HTTP 402 + on-chain escrow.

## How It Works

```
Agent A                    Agent B
   β”‚                          β”‚
   β”‚ GET /api/data            β”‚
   β”‚ ─────────────────────►   β”‚
   β”‚                          β”‚
   β”‚ 402 Payment Required     β”‚
   β”‚ X-Price: 0.01 USDC       β”‚
   β”‚ ◄─────────────────────   β”‚
   β”‚                          β”‚
   β”‚ Lock funds in escrow     β”‚
   β”‚ ══════════════════════►  β”‚ (on-chain)
   β”‚                          β”‚
   β”‚ GET /api/data            β”‚
   β”‚ X-Payment-Proof: 0x...   β”‚
   β”‚ ─────────────────────►   β”‚
   β”‚                          β”‚
   β”‚ 200 OK + data            β”‚
   β”‚ ◄─────────────────────   β”‚
   β”‚                          β”‚
   β”‚ Release escrow           β”‚
   β”‚ ◄══════════════════════  β”‚ (on-chain)
```

## Quick Start

### As a Buyer (Paying Agent)

```typescript
import { X402Client } from './x402-client';

const client = new X402Client({
  wallet: '0x...',
  privateKey: process.env.PRIVATE_KEY,
  facilitatorUrl: 'http://localhost:8403'
});

// Call a paid API - payment handled automatically
const response = await client.fetch('http://agent-b.local/api/sensor-data');
console.log(response.data);
console.log(`Paid: ${response.paymentAmount} USDC`);
```

### As a Seller (Paid Agent)

```typescript
import { X402Server } from './x402-server';
import { Hono } from 'hono';

const app = new Hono();
const x402 = new X402Server({
  wallet: '0x...',
  facilitatorUrl: 'http://localhost:8403'
});

// Protect an endpoint with payment requirement
app.get('/api/sensor-data', x402.protect({ price: 0.01 }), (c) => {
  return c.json({ temperature: 23.5, humidity: 45 });
});

// Free endpoint
app.get('/api/status', (c) => {
  return c.json({ online: true });
});
```

## Run the Facilitator

The facilitator coordinates payments and monitors escrow:

```bash
cd apps/x402-facilitator
bun run start
```

```
πŸ”· X402 Facilitator Started
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ“ HTTP:      http://0.0.0.0:8403
πŸ”Œ WebSocket: ws://0.0.0.0:8403
⛓️  Escrow:    0x5FbDB2315678afecb367f032d93F642f64180aa3
🌐 Provider:  http://localhost:8545
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

## Local Development

```bash
# Start local blockchain
anvil

# Deploy escrow contract
cd contracts && forge script script/Deploy.s.sol --broadcast

# Start facilitator
cd apps/x402-facilitator && bun run start

# Run example agents
bun run dev:alice   # Seller on :3001
bun run dev:bob     # Buyer on :3002
```

## Payment Flow

1. **Request** β€” Buyer calls seller API
2. **Challenge** β€” Seller returns 402 with price
3. **Lock** β€” Buyer locks funds in escrow contract
4. **Proof** β€” Buyer retries with payment proof header
5. **Deliver** β€” Seller returns data
6. **Release** β€” Escrow releases funds to seller

If seller doesn't deliver, buyer can dispute and get refund.

## Headers

| Header | Direction | Description |
|--------|-----------|-------------|
| `X-Price` | Response | Required payment amount |
| `X-Payment-Address` | Response | Seller's wallet |
| `X-Payment-Proof` | Request | Transaction hash proving payment |
| `X-Escrow-Id` | Both | Escrow transaction ID |

## Chains Supported

- Local (Anvil)
- Base
- Arbitrum
- Any EVM chain

## Why Escrow?

- **Trustless** β€” No reputation needed
- **Atomic** β€” Payment and delivery linked
- **Reversible** β€” Dispute mechanism for non-delivery
- **Cheap** β€” L2s make this practical

## Links

- [HTTP 402 Spec](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/402)
- [QUSD Qualia](https://github.com/QUSD-ai/qualia)
- [A2A Protocol](https://a2a-protocol.org)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.