Install
openclaw skills install x402-paywall-kitDetect and pay x402 crypto paywalls automatically. When your agent gets a 402 Payment Required response with x402 JSON, this skill handles payment via Coinba...
openclaw skills install x402-paywall-kitAutomatically detect and pay x402 crypto paywalls when your AI agent encounters HTTP 402 Payment Required responses.
Activate this skill when an HTTP response returns status 402 Payment Required and the response body contains an x402Version field with an accepts array describing payment options.
Detection pattern:
402x402Version (number) and accepts (array of payment requirements)PAYMENT-REQUIRED (base64-encoded payment requirements)npm install @x402-kit/agent @x402-kit/shared
import { createAgentFetch } from "@x402-kit/agent";
const agentFetch = createAgentFetch({
walletPrivateKey: process.env.X402_WALLET_PRIVATE_KEY as `0x${string}`,
network: "eip155:8453", // Base mainnet
policy: {
maxPerRequest: "1.00", // Max 1 USDC per request
maxDailySpend: "10.00", // Max 10 USDC per day
allowedNetworks: ["eip155:8453"],
allowedAssets: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"], // USDC on Base
requireHumanApproval: false,
},
logFilePath: "./x402-payments.jsonl",
});
// Use agentFetch exactly like regular fetch
const response = await agentFetch("https://api.example.com/premium/data");
const data = await response.json();
X-PAYMENT header| Variable | Required | Description |
|---|---|---|
X402_WALLET_PRIVATE_KEY | Yes | Hex private key (with 0x prefix) of a wallet funded with USDC on Base |
The policy object controls what the agent is allowed to spend:
interface X402Policy {
maxPerRequest: string; // Max USDC per single request (e.g., "1.00")
maxDailySpend: string; // Max USDC per day (e.g., "10.00")
allowedNetworks: string[]; // CAIP-2 networks (e.g., ["eip155:8453"])
allowedAssets: string[]; // Token contract addresses
domainAllowlist?: string[]; // Only pay these domains (optional)
domainDenylist?: string[]; // Never pay these domains (optional)
requireHumanApproval: boolean;
}
| Network | CAIP-2 ID | USDC Address |
|---|---|---|
| Base (mainnet) | eip155:8453 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Base Sepolia (testnet) | eip155:84532 | 0x036CbD53842c5426634e7929541eC2318f3dCF7e |
interface AgentFetchConfig {
walletPrivateKey: Hex; // From env: X402_WALLET_PRIVATE_KEY
policy: X402Policy; // Spending rules
network: Network; // CAIP-2 format (e.g., "eip155:8453")
spendFilePath?: string; // Daily spend persistence (default: ".x402/daily-spend.json")
logFilePath?: string; // Payment log file path
rpcUrl?: string; // Custom JSON-RPC URL
tokenDecimals?: number; // Token decimals (default: 6 for USDC)
}
Agent calls api.example.com/premium, gets 402, pays 0.10 USDC, gets data:
const agentFetch = createAgentFetch({
walletPrivateKey: process.env.X402_WALLET_PRIVATE_KEY as `0x${string}`,
network: "eip155:8453",
policy: {
maxPerRequest: "0.50",
maxDailySpend: "5.00",
allowedNetworks: ["eip155:8453"],
allowedAssets: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
requireHumanApproval: false,
},
});
const response = await agentFetch("https://api.example.com/premium/weather");
// First request returns 402 -> agent auto-pays 0.10 USDC -> retries -> gets 200 with data
const agentFetch = createAgentFetch({
walletPrivateKey: process.env.X402_WALLET_PRIVATE_KEY as `0x${string}`,
network: "eip155:8453",
policy: {
maxPerRequest: "1.00",
maxDailySpend: "20.00",
allowedNetworks: ["eip155:8453"],
allowedAssets: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
domainAllowlist: ["api.trusted-service.com", "data.partner.io"],
requireHumanApproval: false,
},
});
const agentFetch = createAgentFetch({
walletPrivateKey: process.env.X402_WALLET_PRIVATE_KEY as `0x${string}`,
network: "eip155:84532", // Base Sepolia testnet
policy: {
maxPerRequest: "10.00",
maxDailySpend: "100.00",
allowedNetworks: ["eip155:84532"],
allowedAssets: ["0x036CbD53842c5426634e7929541eC2318f3dCF7e"], // USDC on Base Sepolia
requireHumanApproval: false,
},
});
X402_WALLET_PRIVATE_KEY from environment variables. Never hardcode it in source files or logs.logFilePath to maintain an audit trail. The log file records every payment attempt (approved, denied, or failed) in JSONL format.domainAllowlist or domainDenylist to restrict which services the agent can pay.eip155:84532) during development. Only switch to mainnet (eip155:8453) for production.Each payment event is logged as a JSON line in the log file:
{
"timestamp": "2026-02-27T12:00:00.000Z",
"url": "https://api.example.com/premium/data",
"amount": "0.1",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"network": "eip155:8453",
"facilitator": "",
"success": true,
"policyDecision": "approved"
}