A skill for making HTTP 402 (x402) micropayments in USDC on Base. It can be funded cross-chain via NEAR Intents or from onramps like Cash App, Revolut, and Robinhood. Designed to be compatible with multiple agent wallet setups.
---
name: x402-pay
description: >
Use this skill when an HTTP request returns 402 Payment Required, when the user wants to call a paid API or x402-protected resource, when they want to discover x402 services, or when they need to fund a wallet across chains. Triggers: a 402 response, "x402", "HTTP 402", "pay for API", "paid endpoint", "find x402 services", "bazaar", "fund my wallet", "top up".
compatibility: >
Requires internet access and `npm install` in x402-pay/. No API keys required. Wallet support: Coinbase Agentic Wallet
(awal, default), raw private key, CDP SDK, Privy server wallets, Turnkey.
metadata:
version: "1.0.0"
openclaw:
homepage: https://github.com/NearDeFi/agent-payments-skill
emoji: "๐ธ"
requires:
bins: ["node", "npm"]
# Dependencies are installed via `npm install` (SKILL.md Step 0); the bundled
# package.json declares them. ClawHub `install` specs only fetch
# global CLI binaries, so they don't apply here.
envVars:
# Raw private key wallet โ provide ONE of these (X402_PRIVATE_KEY is canonical; the rest are aliases)
- { name: X402_PRIVATE_KEY, required: false, description: "Raw private key wallet (canonical)" }
- { name: PRIVATE_KEY, required: false, description: "Raw private key wallet (alias for X402_PRIVATE_KEY)" }
- { name: WALLET_PRIVATE_KEY, required: false, description: "Raw private key wallet (alias for X402_PRIVATE_KEY)" }
- { name: ETH_PRIVATE_KEY, required: false, description: "Raw private key wallet (alias for X402_PRIVATE_KEY)" }
- { name: AGENT_PRIVATE_KEY, required: false, description: "Raw private key wallet (alias for X402_PRIVATE_KEY)" }
# Base RPC (optional โ defaults to public Base mainnet RPC)
- { name: BASE_RPC_URL, required: false, description: "Custom Base RPC URL (defaults to public Base mainnet RPC)" }
- { name: BASE_RPC_KEY, required: false, description: "Optional Base RPC auth token (sent as Authorization: Bearer)" }
# Coinbase CDP SDK wallet
- { name: CDP_API_KEY_ID, required: false, description: "Coinbase CDP SDK wallet โ API key id" }
- { name: CDP_API_KEY_SECRET, required: false, description: "Coinbase CDP SDK wallet โ API key secret" }
- { name: CDP_WALLET_SECRET, required: false, description: "Coinbase CDP SDK wallet โ wallet secret" }
- { name: CDP_WALLET_ADDRESS, required: false, description: "Coinbase CDP SDK wallet โ wallet address (optional)" }
# Privy server wallet
- { name: PRIVY_APP_ID, required: false, description: "Privy server wallet โ app id" }
- { name: PRIVY_APP_SECRET, required: false, description: "Privy server wallet โ app secret" }
- { name: PRIVY_WALLET_ID, required: false, description: "Privy server wallet โ wallet id" }
- { name: PRIVY_WALLET_ADDRESS, required: false, description: "Privy server wallet โ wallet address (optional)" }
# Turnkey wallet
- { name: TURNKEY_API_PUBLIC_KEY, required: false, description: "Turnkey wallet โ API public key" }
- { name: TURNKEY_API_PRIVATE_KEY, required: false, description: "Turnkey wallet โ API private key" }
- { name: TURNKEY_ORGANIZATION_ID, required: false, description: "Turnkey wallet โ organization id" }
- { name: TURNKEY_SIGN_WITH, required: false, description: "Turnkey wallet โ signing address / key handle" }
---
# x402 โ HTTP-Native Payments
x402 gates API resources behind USDC micropayments using HTTP `402 Payment Required`.
---
## Step 0: Setup
Before running any script, install dependencies in the skill directory (once per environment):
```bash
cd <skills-dir>/x402-pay
npm install
```
No API keys required.
---
## Step 1: Detect your wallet
Read `references/detecting-wallets.md` to choose which wallet to use. Once you've picked one, return here and continue from Step 2.
---
## Step 2: Is the Service Known?
If you already have a specific service URL in mind that returned 402 payment required, skip straight to `Step 3: Get the Service Details`.
Otherwise continue to `Step 2a: Find a Service`
## Step 2a: Find a Service
List all available services from x402-list and pick the most appropriate one:
```bash
node scripts/search-services.mjs search
```
If nothing suitable is found, try the Coinbase bazaar:
```bash
node scripts/search-services.mjs search <keyword> --source bazaar
```
If still nothing, search the internet for x402 services matching the user's need.
## Step 3: Get the Service Details
Once you have a service URL, get its full details (schemas, parameters, examples):
```bash
node scripts/search-services.mjs details <resource-url>
```
Then preview the live price โ this reads the 402 challenge **without paying** and is wallet-independent:
```bash
node scripts/check-price.mjs <url> [--method GET|POST] [--body '{"key":"value"}']
```
Note this price: you'll use it in Step 4 to check whether your balance is sufficient (and, if funding, how much to deposit), and show it to the user before paying in Step 5.
### Example working service
```bash
https://x402.ottoai.services/crypto-news
```
---
## Step 4: Check Balance
Check your wallet's USDC balance on Base โ see `references/wallet-flows.md` for the method for your wallet (if you don't already know it) โ and compare it against the price you previewed in Step 3.
- **Balance โฅ service price** โ proceed to Step 5
- **Balance < service price** โ fund it: Read `references/near-intents-funding.md` for the cross-chain funding flow. Always use NEAR intents to fund the wallet if the balance is low. If the user has no crypto to swap from, the **onramp** path (`references/onramp-funding.md`) funds the wallet from Cash App / Robinhood / Revolut.
**Gas:** No ETH needed โ you sign off-chain only. The x402 facilitator submits the on-chain transaction and covers gas. This applies to all wallet types.
---
## Step 5: Pay
**Always show the price before paying. Confirm with user before paying.**
Show the user the price you previewed in Step 3 (if significant time has passed, re-run `check-price.mjs` in case it changed). **Always get their confirmation before paying โ for any amount.** Then pay the endpoint using your wallet โ see `references/wallet-flows.md` for the method for your wallet (if not already known).
---
## Step 6: Confirm
Report the response body and any transaction hash to the user.
---
## Rules
- **Always ask the user before executing any command.** Show the exact command you intend to run and wait for explicit approval before running it โ this applies to wallet, payment, and funding commands.
- Abide by configured safeguards such as wallet spend limits and allowlists.
- When funding, always confirm the refund destination (address, chain, and origin-chain vs. NEAR Intents balance) with the user before any deposit.
- Never pay silently โ always show the decoded price first
- Confirm with user before any payment
- Always report the tx hash after a successful payment
don't have the plugin yet? install it then click "run inline in claude" again.