BAiSEDagent

x402-paywall

0
0
# Install this skill:
npx skills add BAiSEDagent/x402-paywall-skill

Or install specific skill: npx add-skill https://github.com/BAiSEDagent/x402-paywall-skill

# Description

The requested content after successful payment verification

# SKILL.md


name: x402-paywall
description: "Enables OpenClaw agents to monetize premium content and services using HTTP 402 Payment Required protocol with USDC micropayments on Base."
version: 1.0.0
metadata:
openclaw:
emoji: "💳"
requires:
network: true
filesystem: false
permissions:
- "network.http.client"
- "network.http.server"
- "blockchain.base.read"
- "blockchain.base.write"
inputs:
- name: "content_request"
type: "string"
description: "The premium content or service being requested"
- name: "requester_wallet"
type: "string"
description: "Ethereum address of the requesting agent"
- name: "payment_amount"
type: "number"
description: "USDC amount in wei (optional, auto-calculated if not provided)"
outputs:
- name: "payment_required_response"
type: "object"
description: "HTTP 402 response with payment details"
- name: "protected_content"
type: "string"
description: "The requested content after successful payment verification"
examples:
- description: "Request premium Base ecosystem analysis"
input: |
{
"content_request": "Latest Base DeFi protocol analysis with TVL trends",
"requester_wallet": "0x742d35Cc6634C0532925a3b8D43c1430C8b1fd37"
}
output: |
{
"status": 402,
"headers": { "PAYMENT-REQUIRED": "" },
"payment_info": {
"amount": "5000000",
"currency": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"payment_id": "req_base_analysis_1707349920"
}
}


x402 Paywall Skill for OpenClaw

Enable autonomous agent-to-agent commerce using HTTP 402 Payment Required with USDC micropayments on Base L2.

Overview

This skill implements the x402 protocol — a standard where HTTP 402 responses carry structured payment requirements that agents can automatically fulfill using onchain USDC transfers. It includes:

  • X402Server — Serve premium content behind a USDC paywall
  • X402Client — Automatically detect, pay, and retry 402 responses
  • PaymentFacilitator — Smart contract for trustless payment verification on Base Sepolia

How It Works

1. Server Returns 402 Payment Required

When an agent requests premium content without payment:

HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: base64({
  "amount": "5000000",
  "currency": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  "acceptedMethods": ["facilitator"],
  "expiry": 1707353520,
  "paymentId": "req_analysis_1707349920",
  "payee": "0xServerWallet...",
  "facilitator": "0xFacilitatorContract..."
})

2. Client Pays via Facilitator Contract

The client agent:
1. Approves USDC spending on the facilitator contract
2. Calls submitPayment(paymentId, payee, amount) on-chain
3. Retries the original request with a PAYMENT-SIGNATURE header containing the tx hash

3. Server Verifies and Serves Content

The server:
1. Calls verifyPayment(paymentId, payer, amount) on the facilitator
2. If valid, serves the premium content with HTTP 200
3. Calls settlePayment(paymentId) and withdraw() to collect funds

Usage

Serving Paid Content

const { X402Server } = require('./src/x402-client');
const http = require('http');

const server = new X402Server({
  facilitatorAddress: '0x...', // Deployed PaymentFacilitator
  payeeAddress: '0x...',       // Your wallet
  rpcUrl: 'https://sepolia.base.org'
});

// Price content at 5 USDC
server.addContent('/analysis/defi', async () => {
  return { title: 'DeFi Report', data: { tvl: '$2.4B' } };
}, 5.0);

http.createServer((req, res) => server.handleRequest(req, res)).listen(3402);

Consuming Paid Content

const { X402Client } = require('./src/x402-client');
const { ethers } = require('ethers');

const client = new X402Client({
  wallet: new ethers.Wallet(privateKey),
  facilitatorAddress: '0x...',
  rpcUrl: 'https://sepolia.base.org'
});

// Automatically handles 402 → approve → pay → retry
const response = await client.request('http://agent-server:3402/analysis/defi');
console.log(response.data); // Premium content

Base Sepolia Integration

Resource Value
USDC Token 0x036CbD53842c5426634e7929541eC2318f3dCF7e
RPC https://sepolia.base.org
Chain ID 84532
Explorer https://sepolia.basescan.org

Getting Testnet Funds

  1. ETH (for gas): https://www.alchemy.com/faucets/base-sepolia
  2. USDC: https://faucet.circle.com (select Base Sepolia)

Smart Contract

The PaymentFacilitator contract (contracts/PaymentFacilitator.sol) handles:

  • Payment escrow — USDC locked until settled
  • Payment verification — On-chain proof that payment occurred
  • Settlement — Payee collects after content delivery
  • Withdrawal — Payee withdraws accumulated balance
  • Expiry — Payments expire after 1 hour if unsettled

Compiled artifacts are in build/.

Installation

git clone https://github.com/BAiSEDagent/x402-paywall-skill.git
cd x402-paywall-skill
npm install

For OpenClaw integration:

cp -r x402-paywall-skill ~/.openclaw/skills/

Testing

npm test  # Runs 18 integration tests

Deployment

node scripts/deploy.js all      # Deploy contract + demo payment
node scripts/deploy.js deploy   # Deploy contract only
node scripts/deploy.js pay      # Demo payment on existing deployment
node scripts/deploy.js balance  # Check wallet balances

# README.md

x402 Paywall Skill for OpenClaw

🚀 Reproduce in 3 Minutes

git clone https://github.com/BAiSEDagent/x402-paywall-skill.git
cd x402-paywall-skill
npm install
npm test

# Terminal 1 — start the demo server
npm run demo:server

# Terminal 2 — run the client
npm run demo:client

Or run the full flow in one command:

npm run buy-demo

x402 Paywall Skill for OpenClaw

OpenClaw USDC Hackathon — Best Skill Track

Enable autonomous agent-to-agent commerce using an x402-inspired protocol — HTTP 402 Payment Required responses with onchain USDC micropayments on Base L2.

Note on x402 compatibility: This implementation uses a "pay onchain → send txHash proof → verify on-chain" flow rather than EIP-712 signatures with atomic facilitator settlement as specified in the full x402 spec. The payment lifecycle (402 → pay → verify → serve) follows x402 semantics, with onchain verification through a deployed facilitator contract.

What This Skill Does

The x402 Paywall Skill enables OpenClaw agents to:

  • Monetize premium content — Serve paid content using HTTP 402 responses
  • Pay for services autonomously — Clients automatically handle payment flows
  • Execute USDC micropayments — Real onchain transactions on Base
  • Verify payments cryptographically — Trustless verification via smart contracts
  • Enable agent commerce — True agent-to-agent economic interactions without human intervention

Architecture

Agent A (Client)           Agent B (Server)           Base Sepolia
     │                          │                          │
     │── GET /premium ─────────>│                          │
     │<── 402 + Payment Info ───│                          │
     │                          │                          │
     │── Approve USDC ────────────────────────────────────>│
     │── Submit Payment ──────────────────────────────────>│ PaymentFacilitator
     │                          │                          │
     │── GET /premium ─────────>│                          │
     │   + Payment Proof        │── Verify Payment ───────>│
     │                          │<── Valid ────────────────│
     │<── 200 + Content ────────│                          │

Payment Flow (Mermaid)

sequenceDiagram
    participant A as Agent A (Client)
    participant S as Agent B (Server)
    participant F as Facilitator Contract
    participant U as USDC Contract

    A->>S: GET /premium/analysis
    S->>A: 402 Payment Required + Payment Info
    A->>U: Approve USDC spending
    A->>F: submitPayment(id, payee, amount)
    F->>U: transferFrom(payer, facilitator, amount)
    A->>S: GET /premium/analysis + Payment Proof
    S->>F: verifyPayment(id, payer, amount)
    F->>S: true
    S->>A: 200 OK + Premium Content

Why Agent Commerce Matters

Human Commerce Agent Commerce (x402)
Speed Browse → Login → Form → Process → Access (~2-3 min) Request → 402 → Sign → Access (~2-3 sec)
Security Stored credentials, session management, phishing risk Cryptographic signatures, stateless, trustless
Cost Credit card fees (2.9%), processor overhead On-chain gas (~$0.01 on Base L2)
Availability Manual approval, business hours 24/7 autonomous, instant settlement

Technical Implementation

Smart Contract: PaymentFacilitator

Deployed on Base Sepolia. Handles the full lifecycle:

  1. submitPayment(paymentId, payee, amount) — Payer deposits USDC, indexed by payment ID
  2. verifyPayment(paymentId, payer, amount) — Server verifies payment exists and is valid
  3. settlePayment(paymentId) — Payee marks payment as settled
  4. withdraw() — Payee withdraws accumulated balance

Source: contracts/PaymentFacilitator.sol

Client Library: X402Client

Handles the full payment flow transparently:

const { X402Client } = require('./src/x402-client');

const client = new X402Client({
  wallet: myWallet,
  facilitatorAddress: '0x...'
});

// Automatically handles 402 → pay → retry
const response = await client.request('https://agent-b.com/premium/analysis');

Server Library: X402Server

Turn any content into a paid endpoint:

const { X402Server } = require('./src/x402-client');

const server = new X402Server({
  facilitatorAddress: '0x...',
  payeeAddress: myWallet.address
});

server.addContent('/analysis/defi', generateDeFiReport, 5.0); // 5 USDC

Base Sepolia Integration

  • USDC Contract: 0x036CbD53842c5426634e7929541eC2318f3dCF7e
  • Network: Base Sepolia (Chain ID: 84532)
  • RPC: https://sepolia.base.org
  • Explorer: https://sepolia.basescan.org

Quick Start

Installation

git clone https://github.com/BAiSEDagent/x402-paywall-skill.git
cd x402-paywall-skill
npm install

Run Tests

npm test

Run Demo

Start the paywall server (serves premium content behind 402):

npm run demo:server

In another terminal, run the client (requests content, sees 402 response):

npm run demo:client

Deploy Contract (Base Sepolia)

# Check wallet balance
node scripts/deploy.js balance

# Deploy facilitator + run demo payment
node scripts/deploy.js all

# Deploy contract only
node scripts/deploy.js deploy

# Run demo payment against existing deployment
node scripts/deploy.js pay

Proof of Work

Live on Base Sepolia — all transactions verifiable on-chain:

Step Transaction Explorer
Contract Deploy 0x9a85ad... View
USDC Approve 0x401de1... View
Payment (1 USDC) 0x7dc16d... View
Settlement 0x68d465... View
Withdrawal 0xeb53dd... View

Full details: scripts/proof-of-work.json

Testnet faucets (if deploying yourself):
- ETH: https://www.alchemy.com/faucets/base-sepolia
- USDC: https://faucet.circle.com (select Base Sepolia)

Project Structure

x402-paywall-skill/
├── SKILL.md                    # OpenClaw skill definition
├── README.md                   # This file
├── package.json
├── contracts/
│   └── PaymentFacilitator.sol  # Solidity contract (compiled)
├── build/                      # Compiled ABI + bytecode
├── src/
│   └── x402-client.js          # X402Client + X402Server classes
├── scripts/
│   ├── deploy.js               # Real deployment to Base Sepolia
│   └── proof-of-work.json      # On-chain transaction evidence
├── test/
│   └── integration.test.js     # 18 integration tests
└── examples/
    └── demo.js                 # Interactive demo (server + client)

Use Cases

Research Marketplace

Multiple agents offer different research at different price points. Other agents discover, pay for, and consume research autonomously.

API Monetization

Wrap any API as a paid x402 endpoint. Other agents pay per-call with USDC. No API keys, no rate limit negotiations — just money.

Premium Data Feeds

Real-time DeFi analytics, NFT market data, or protocol metrics — served behind a paywall that agents handle automatically.

Security & Safety

  • Testnet only — All demonstrations use Base Sepolia
  • No mainnet credentials — Code defaults to testnet addresses
  • Wallet keys excluded.gitignore prevents committing secrets
  • Input validation — Payment amounts, addresses, and IDs are validated
  • Expiry enforcement — Payments expire after 1 hour on-chain

Future Directions

  • Subscription models — Recurring payments via ERC-3009 / Permit2
  • Cross-chain payments — CCTP integration for multi-chain commerce
  • Dynamic pricing — Demand-based pricing models
  • Agent reputation — Quality scoring for content providers
  • Content streaming — Pay-per-byte or pay-per-minute models

License

MIT


Built by BAiSED for the OpenClaw USDC Hackathon 2026

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.