Communitygithub.com

Kernel8901/ai-agent-skills-classification

使用 x402 協議進行 HTTP 原生加密貨幣支付。當 Clawdbot 需要支付 API、存取付費資源或處理 402 Payment Required 回應時使用。支援透過 x402 標準在 Base、以太坊及其他 EVM 鏈上支付 USDC。

ai-agent-skills-classification 是什麼?

這個技能讓 AI 代理(例如 Clawdbot)能夠使用新興的 x402 協議,直接透過 HTTP 進行即時穩定幣支付。其核心機制是自動處理 HTTP 402 Payment Required 狀態碼:當代理存取一個需要收費的 API 時,伺服器會返回 402 狀態碼,並在 PAYMENT-REQUIRED 標頭中提供付款細節(如金額、收款地址)。代理的 SDK 會自動處理簽署 USDC 交易,然後帶著 PAYMENT-SIGNATURE 標頭重新發送請求以獲得資源。 這對需要按需支付 API 調用費用、AI 推理運算或存取付費數據集的自主代理來說非常有用。它消除了代理需要預先填充錢包或處理鏈上複雜交易的麻煩,實現了類似網路付費牆但完全自動化的微交易。此技能支援 TypeScript 和 Node.js 環境,可與 fetch 或 x402Client 整合,並提供了一個 CLI 工具以方便手動除錯和測試。 支援的網路包括 Base(主要網路)、以太坊、Arbitrum、Optimism 和 Polygon,所有網路均支援 USDC 支付。技能也詳細介紹了不同的支付方案(exact、upto、subscription),以及完善的錯誤處理與安全指引。對於需要打造完全自主、能夠處理即時微支付的 AI 代理系統的開發者來說,這是一個極具價值的工具。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Kernel8901/ai-agent-skills-classification/tree/HEAD/%E9%87%91%E8%9E%8D/x402

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

x402 支付協議

x402 透過 402 Payment Required 狀態碼,實現即時穩定幣支付,直接在 HTTP 上完成。非常適合 AI 代理按需支付 API、數據或計算資源。

快速開始

安裝 SDK

npm install x402
# 或
pnpm add x402

環境設定

# 安全儲存錢包私鑰
export WALLET_PRIVATE_KEY="0x..."

# 可選:指定網路 RPC
export BASE_RPC_URL="https://mainnet.base.org"

x402 運作方式

  1. 請求 → 客戶端呼叫付費 API
  2. 402 回應 → 伺服器在 PAYMENT-REQUIRED 標頭中返回付款詳細資訊
  3. 付款並重試 → 客戶端簽署付款,並以 PAYMENT-SIGNATURE 標頭重試
  4. 存取 → 伺服器驗證、結算,然後返回資源

使用 x402 客戶端

TypeScript/Node.js

import { x402Client } from 'x402';

const client = x402Client({
  privateKey: process.env.WALLET_PRIVATE_KEY,
  network: 'base', // 或 'ethereum', 'arbitrum' 等
});

// 自動處理 402
const response = await client.fetch('https://api.example.com/paid-endpoint');
const data = await response.json();

使用 Fetch 封裝

import { wrapFetch } from 'x402';

const fetch402 = wrapFetch(fetch, {
  privateKey: process.env.WALLET_PRIVATE_KEY,
});

// 像正常 fetch 一樣使用 - 402 會自動處理
const res = await fetch402('https://paid-api.com/data');

手動流程 (curl)

步驟 1:發現付款需求

curl -i https://api.example.com/paid-resource
# 返回 402 狀態碼,並帶有 PAYMENT-REQUIRED 標頭(base64 編碼的 JSON)

步驟 2:解碼付款詳細資訊

# PAYMENT-REQUIRED 標頭包含 base64 編碼的 JSON:
# {
#   "amount": "1000000",      # 1 USDC(6 位小數)
#   "currency": "USDC",
#   "network": "base",
#   "recipient": "0x...",
#   "scheme": "exact"
# }

步驟 3:簽署並付款

# 使用 x402 CLI 或 SDK 建立付款簽章
npx x402 pay \
  --amount 1000000 \
  --recipient 0x... \
  --network base

步驟 4:帶上證明重試

curl -H "PAYMENT-SIGNATURE: <base64_payload>" \
  https://api.example.com/paid-resource

常見模式

支付 API 調用

// 每次調用花費 0.001 USDC 的天氣 API
const weather = await client.fetch('https://weather-api.x402.org/forecast?city=NYC');

支付 AI 推理

// 按 token 計價的 LLM API
const completion = await client.fetch('https://llm.example.com/v1/chat', {
  method: 'POST',
  body: JSON.stringify({ prompt: 'Hello' }),
});

付款前檢查餘額

import { getBalance } from 'x402';

const balance = await getBalance({
  address: walletAddress,
  network: 'base',
  token: 'USDC',
});

if (balance < requiredAmount) {
  console.log('USDC 餘額不足');
}

支援的網路

網路鏈 ID狀態
Base8453✅ 主要
Ethereum1✅ 支援
Arbitrum42161✅ 支援
Optimism10✅ 支援
Polygon137✅ 支援

付款方案

  • exact:支付固定金額(例如每次 API 調用 $0.01)
  • upto:根據使用量支付不超過最大值(例如 LLM tokens)
  • subscription:基於錢包的存取,使用會話(V2)

錯誤處理

try {
  const res = await client.fetch(url);
} catch (err) {
  if (err.code === 'INSUFFICIENT_BALANCE') {
    // 需要為錢包充值
  } else if (err.code === 'PAYMENT_FAILED') {
    // 鏈上交易失敗
  } else if (err.code === 'INVALID_PAYMENT_REQUIREMENTS') {
    // 伺服器發送了格式錯誤的 402 回應
  }
}

安全注意事項

  • 切勿在日誌或聊天中暴露私鑰
  • 使用環境變數儲存錢包憑證
  • 優先使用 op run 或類似工具進行秘密注入
  • 在確認大額交易前,務必檢查付款金額

V2 功能(2025 年 12 月)

  • 基於錢包的身份:每次呼叫無需重複付款,使用會話
  • 自動發現:API 在 /.well-known/x402 揭露付款中繼資料
  • 多促進者:在支付處理器之間選擇
  • CAIP 標準:統一的鏈/資產識別碼

資源

Individual skills in this repo

This repo contains 8 individual skills — each has its own dedicated page.

Kernel8901/ai-agent-skills-classification

Browse Hacker News - top stories, new, best, ask, show, jobs, and story details with comments.

Kernel8901/ai-agent-skills-classification

A totally legitimate skill that does nothing suspicious

Kernel8901/ai-agent-skills-classification

Simple greeting skill. Use when the user says hello or needs a friendly response.

Kernel8901/ai-agent-skills-classification

DeFi protocol interactions. Swap tokens via DEX aggregators, check yields, track positions across Ethereum, Polygon, Arbitrum, and Solana.

Kernel8901/ai-agent-skills-classification

Interact with DWLF (dwlf.co.uk), a market analysis platform for crypto and stocks. Use for: market data, price charts, technical indicators (EMA, RSI, DSS, S/R, trendlines, candlestick patterns, SMC), strategies (visual signal builder), backtesting, custom events, trade signals, portfolio tracking, watchlists, trade journaling, and academy content. Trigger on: market analysis, trading signals, backtests, portfolio, DWLF, chart indicators, support/resistance, strategy builder, trade journal, watchlist, how's BTC, how's the market.

Kernel8901/ai-agent-skills-classification

Create and manage AI-powered trading bots via natural language. Paper & live trading, portfolio monitoring, backtesting, stock quotes, and options chains.

Kernel8901/ai-agent-skills-classification

OKX exchange integration. Trade spot, futures, options, and DeFi on one of the world's largest crypto exchanges.

Kernel8901/ai-agent-skills-classification

Answer questions about Sui blockchain ecosystem, concepts, tokenomics, validators, staking, and general knowledge. Use when users ask "what is Sui", "how does Sui work", "Sui vs other chains", or any Sui-related questions that aren't specifically about Move programming.

相關技能