💻

x402 pay

👤 pivortex 📦 v1.0.2 ⭐ 4.6 ⬇️ 449 下载
💻 开发编程 免费

📖 技能介绍


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 x402 wallet", "top up my x402 wallet". compatibility: > No API keys required. Works out of the box with the default Coinbase Agentic Wallet (awal) — just an email address to log in. Also supports raw private key, CDP SDK, Privy, and Turnkey if already configured. Requires internet access. metadata: version: "1.0.2" 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):

cd <skills-dir>/x402-pay
npm install

No API keys required. The default wallet (awal) works with just an email address. CDP, Privy, and Turnkey wallets are also supported if already configured.


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:

node scripts/search-services.mjs search

If nothing suitable is found, try the Coinbase bazaar:

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):

node scripts/search-services.mjs details <resource-url>

Then preview the live price — this reads the 402 challenge without paying and is wallet-independent:

小葱技能有更好的技能skills插件。

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

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). Always pass the confirmed price, unpadded, as the payment command's hard cap — --max-price <usdc> for pay.mjs, --max-amount <atomic> for awal, MAX_PRICE in the managed-signer template — so a quote raised at payment time fails closed instead of overcharging.

This rule applies to every payment method, including wallets not covered in references/wallet-flows.md: if the wallet's tooling has a spend-cap option, pass the confirmed price there; otherwise plug its EIP-712 signer into the managed-signer template (it is wallet-agnostic — any wallet that can sign typed data works) so MAX_PRICE is enforced. Never pay through a mechanism that cannot enforce the confirmed price as a hard cap at payment time.


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.
  • Never pay through a mechanism that cannot enforce the user-confirmed price as a hard cap at payment time — for wallets without one, route signing through the managed-signer template in references/wallet-flows.md.
  • If a wallet's authentication is missing or expired (e.g. awal is signed out), stop immediately and report it, telling the user what login action to take. Never attempt to recover access yourself: do not search the user's files, email, message history, or browser/app storage for keys, session tokens, or OTP codes, and do not retry authentication repeatedly.
  • 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

🤖 AI 评测

这个技能质量不错,能帮助 AI 代理轻松完成 x402 付费 API 调用。它开箱即用,支持多种钱包,跨链充值选项丰富。最大的亮点是安全设计完善——付款前会预览价格、设置支付上限,失败自动中止。文档和风险提示也很充分。不过它依赖多个第三方服务(Coinbase、NEAR Intents 等),遇到问题时排查可能比较麻烦;功能较复杂,新手需要一定学习成本。总体而言,这是一款成熟度高、风险意识强的支付技能,适合需要 AI 代理进行付费 API 调用的场景。

📊 多维度评分

适应性4.7
规范性4.7
有效性4.7
可靠性4.5
可信度4.3

📁 包含文件 (23 个)

📄 DISCLOSURES.txt 3.3 KB
📄 LICENSE-THIRD-PARTY.txt 36.9 KB
📄 LICENSE.txt 909 B
📄 NOTICE.txt 4.8 KB
📄 README.md 5.7 KB
📄 SKILL.md 8.5 KB
📄 _meta.json 127 B
📄 license.thirdparty.txt 2.4 KB
📄 package.json 176 B
📄 references/detecting-wallets.md 3.8 KB
📄 references/near-intents-funding.md 11.7 KB
📄 references/onramp-funding.md 4 KB
📄 references/wallet-flows.md 10 KB
📄 scripts/check-price.mjs 3.3 KB
📄 scripts/cli-args.mjs 631 B
📄 scripts/cost-guard.mjs 1.2 KB
📄 scripts/load-env.mjs 675 B
📄 scripts/near-intents.mjs 11.7 KB
📄 scripts/pay.mjs 7.1 KB
📄 scripts/search-services.mjs 7.6 KB
📄 scripts/wallet.mjs 3.5 KB
📄 scripts/x402-options.mjs 2.7 KB
📄 skill-card.md 2.9 KB