Skip to content

Scottcjn/openclaw-x402

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openclaw-x402

BCOS Certified Drop-in x402 payment middleware for Flask APIs. Add machine-to-machine payments to any OpenClaw platform in 5 lines.

Part of the Beacon Protocol ecosystem — provides the payment layer for beacon_skill.x402_bridge and the Compute Marketplace.

Install

pip install openclaw-x402

Quick Start

from flask import Flask, jsonify
from openclaw_x402 import X402Middleware

app = Flask(__name__)
x402 = X402Middleware(app, treasury="0xYourBaseAddress")

@app.route("/api/premium/data")
@x402.premium(price="10000", description="Premium data export")  # $0.01 USDC
def premium_data():
    return jsonify({"data": "your premium content"})

# Free endpoints work normally — no decorator needed
@app.route("/api/public/data")
def public_data():
    return jsonify({"data": "free content"})

How It Works

  1. Agent hits your premium endpoint
  2. Gets back HTTP 402 with payment instructions (USDC amount, treasury address, facilitator URL)
  3. Agent pays via Coinbase wallet on Base chain
  4. Agent retries with X-PAYMENT header containing tx hash
  5. Middleware verifies payment via Coinbase facilitator
  6. Access granted

Free Mode

Set price="0" to pass all requests through without payment — useful for testing the flow before charging.

@x402.premium(price="0", description="Free for now")
def free_premium():
    return jsonify({"data": "free during testing"})

Configuration

Env Var Purpose
CDP_API_KEY_NAME Coinbase Developer Platform API key name
CDP_API_KEY_PRIVATE_KEY CDP API private key

Get credentials at portal.cdp.coinbase.com.

Contract Addresses (Base Mainnet)

Token Address
USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
wRTC 0x5683C10596AaA09AD7F4eF13CAB94b9b74A669c6
Aerodrome Pool 0x4C2A0b915279f0C22EA766D58F9B815Ded2d2A3F

Ecosystem

License

MIT

About

Drop-in x402 payment middleware for Flask APIs. Machine-to-machine payments on Base chain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

 
 
 

Contributors

Languages