Skip to main content

openclaw-x402

The shortest path from agent demo to agent commerce.

An MCP server where tools cost RTC to use. Claude calls a paid tool and it just works -- payment happens automatically via the x402 protocol (HTTP 402 Payment Required).

Also includes drop-in Flask middleware for adding x402 payments to any REST API.

5-Second Demo

from openclaw_x402.mcp_server import mcp, _gate, _paid_result

@mcp.tool
def premium_export(format: str = "json", payment_token: str = "") -> str:
    """[0.1 RTC] Premium data export."""
    err = _gate(payment_token, 0.1, "premium_export", "Premium data export")
    if err:
        return err
    return _paid_result({"data": "your premium content", "format": format}, 0.1, payment_token)

That is a paid MCP tool. Agents that call it without paying get a 402 response with payment instructions. Agents that pay 0.1 RTC get the data.

Install

pip install openclaw-x402

How It Works

Agent calls tool
    |
    v
No payment token? -----> Return 402 + price + payment instructions
    |                          |
    |                     Agent signs RTC transfer to treasury
    |                          |
    |                     Agent retries with payment_token
    |
Has payment token
    |
    v
Verify on RustChain -----> Invalid? Return error + retry instructions
    |
    v
Execute tool, return result

Claude Desktop / Claude Code Setup

Add to your MCP config (~/.claude/claude_desktop_config.json or project .mcp.json):

{
  "mcpServers": {
    "openclaw-x402": {
      "command": "python",
      "args": ["-m", "openclaw_x402"],
      "env": {
        "RUSTCHAIN_NODE": "https://50.28.86.131",
        "TREASURY_WALLET": "your-wallet-id",
        "X402_TESTNET": "1"
      }
    }
  }
}

Claude now has access to paid tools. It can call list_prices (free) to see what is available, then pay for premium_search, miner_profile, or bcos_report.

Built-in Tools

Tool Price Description
list_prices FREE List all tools and prices
network_status FREE RustChain node health
premium_search 0.1 RTC Search the RustChain ledger
miner_profile 0.05 RTC Miner hardware fingerprint profile
bcos_report 0.25 RTC BCOS trust report for a GitHub repo

Add Your Own Paid Tools

from openclaw_x402.mcp_server import mcp, _gate, _paid_result

@mcp.tool
def gpu_inference(prompt: str = "", model: str = "llama-7b", payment_token: str = "") -> str:
    """[0.5 RTC] Run GPU inference job.

    Args:
        prompt: The input prompt.
        model: Model name to use.
        payment_token: RTC payment JSON. Omit to get payment instructions.
    """
    err = _gate(payment_token, 0.5, "gpu_inference", "Run GPU inference job")
    if err:
        return err
    result = run_model(prompt, model)
    return _paid_result({"output": result}, 0.5, payment_token)

# Free tools use the normal FastMCP decorator
@mcp.tool
def check_queue() -> str:
    """[FREE] Check GPU job queue length."""
    return '{"queue_length": 3}'

Payment Token Format

When an agent pays for a tool, it includes a payment_token argument:

{
  "tx_id": "abc123...",
  "from": "agent-wallet-id",
  "amount": 0.1
}

The server verifies this transaction exists on RustChain before executing the tool. In testnet mode (X402_TESTNET=1), verification is relaxed for development.

Flask Middleware (REST APIs)

For traditional HTTP APIs (not MCP), use the Flask middleware:

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"})

The Flask middleware uses USDC on Base chain via Coinbase facilitator. The MCP server uses RTC on RustChain. Same pattern, two payment rails.

Environment Variables

Variable Default Purpose
RUSTCHAIN_NODE https://50.28.86.131 RustChain node URL
TREASURY_WALLET openclaw-x402-treasury Wallet receiving payments
X402_TESTNET 1 Accept payments on trust (dev mode)
RC_ADMIN_KEY Admin key for verified transfers

Why x402 + MCP

HTTP 402 has been a reserved status code since 1999. x402 gives it a real protocol. MCP gives AI agents a tool interface. Together: agents discover tools, see prices, pay, and use them -- no human in the loop.

This is the infrastructure layer for agent commerce. Every GPU cluster, every API, every dataset can become a paid tool that any agent can use.

License

MIT

Metadata

Release files for openclaw-x402 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openclaw-x402 0.2.0
File Size Uploaded Provenance
openclaw_x402-0.2.0.tar.gz 12.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for openclaw-x402 0.2.0
File Interpreter ABI Platform
openclaw_x402-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / openclaw_x402-0.2.0.tar.gz

Download URL openclaw_x402-0.2.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c67b3d2fe9d866c2319ab0a4d9f40575243e8860c1001cf0022577ffa22572f5
BLAKE2b-256 checksum
How to use checksums
2c6208fc0b30092756e9412e6bb3b2ed2910b090caa1557ebd51bfe1951cc9fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / openclaw_x402-0.2.0-py3-none-any.whl

Download URL openclaw_x402-0.2.0-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7b70eb3283088dde4c21eb5ac5ac14f1b85f8c2e7641990a7da0e8a75f88cb5
BLAKE2b-256 checksum
How to use checksums
83ac4b1a7801d711e5d037ad95997f09fba35a1e1b1cc016d0722724643d64d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for openclaw-x402 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page