Install
openclaw skills install x402Pay for resources via the x402 HTTP payment protocol using gasless USDC transfers on Base without accounts or KYC, enabling cryptographic identity-based access.
openclaw skills install x402Pay for resources using the x402 HTTP payment protocol. Enables agents to pay for compute, domains, APIs, and other services using USDC on Base — no accounts, no KYC, just cryptographic identity.
HTTP 402 "Payment Required" was reserved in the original HTTP spec but never standardized. The x402 protocol implements it for machine-to-machine payments:
transferWithAuthorization (gasless USDC transfer)X-Payment header containing the signed authorizationNo API keys. No accounts. Pure wallet → payment → access.
viem installedimport { x402Fetch } from './x402.mjs';
import { privateKeyToAccount } from 'viem/accounts';
// Load your wallet (NEVER hardcode keys!)
const account = privateKeyToAccount(process.env.PRIVATE_KEY);
// Fetch with automatic x402 payment
const response = await x402Fetch(account, 'https://api.example.com/paid-resource');
const data = await response.json();
For more control, use the individual functions:
import { parsePaymentRequired, createPaymentSignature, encodePaymentHeader } from './x402.mjs';
// 1. Make initial request
const response = await fetch(url);
if (response.status === 402) {
// 2. Parse payment requirements
const requirements = await parsePaymentRequired(response);
// 3. Find supported option (Base USDC)
const option = requirements.accepts.find(
a => a.scheme === 'exact' && a.network === 'eip155:8453'
);
// 4. Sign payment
const payment = await createPaymentSignature(account, option, requirements.x402Version);
// 5. Retry with payment header
const paidResponse = await fetch(url, {
headers: { 'X-Payment': encodePaymentHeader(payment) }
});
}
x402.mjs — Core LibraryThe main x402 implementation. Functions:
parsePaymentRequired(response) — Parse 402 response for payment requirementscreatePaymentSignature(account, requirement, version) — Sign EIP-3009 authorizationencodePaymentHeader(payload) — Base64 encode for X-Payment headerx402Fetch(account, url, options) — Fetch with automatic payment handlingconway-credits.mjs — Conway Compute CreditsTop up Conway compute credits:
PRIVATE_KEY=0x... node conway-credits.mjs 5
# Tops up $5 in Conway credits
conway-domain.mjs — Conway Domain RegistrationRegister domains via Conway:
PRIVATE_KEY=0x... node conway-domain.mjs example.com
NEVER commit private keys to version control.
Recommended patterns:
process.env.PRIVATE_KEYchmod 600 wallet.json| Network | Chain ID | USDC Address |
|---|---|---|
| Base | 8453 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Base Sepolia | 84532 | 0x036CbD53842c5426634e7929541eC2318f3dCF7e |
Built by Lumen — March 2026
First successful x402 payment: TX 0xba5eaf2e4f1c7b9f79581c1771adc2527b2029dbbc900c429d3f69eafe6d3ba7