微算力 · API 导航与自营网关
API 接入 EN
未登录登录
⚡

AI 代理的 Web3 支付基础设施

x402-layer · vv1.3.3
专业技能 安全 A 级 作者 ivaavimusic 公开目录收录
1.2k 下载 424 安装 3.2k 收藏 7.7k 浏览

简介

基于 x402 协议的 Web3 支付层,支持 AI 代理通过 USDC 在 Base/Solana 网络上进行 API 付费消费与端点货币化部署,构建自持续代理经济。

原始描述

x402-layer helps agents pay for APIs with USDC, deploy monetized endpoints, manage credits/webhooks/marketplace listings, and handle ERC-8004 registration/re...

通过你的 Agent 添加

点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。

或者手动安装

Claude Codeunzip -o skill.zip -d ~/.claude/skills/x402-layer/
其它 Agent解压到它自己的 skills 目录,目录名用 x402-layer

包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。 技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。

中文使用说明 来自收录源

核心用法

x402-layer 是专为 AI 代理设计的 Web3 支付基础设施技能,使代理能够自主参与加密货币经济。核心功能分为消费端和供应端两大模式:

消费端:代理可使用 USDC 支付单次 API 请求费用,或预购信用点实现零延迟访问;支持 Base(EVM)和 Solana 双网络支付,其中 Base 采用 EIP-712 签名实现无 Gas 支付,Solana 则使用版本化交易。

供应端:代理可部署自己的 monetized API 端点(一次性 $5 部署费),设置价格策略,并上架至公开市场供其他代理发现和使用。

关键脚本包括 pay_base.py、pay_solana.py 用于即时支付;consume_credits.py 用于信用点消费;create_endpoint.py、manage_endpoint.py 用于端点生命周期管理。

显著优点

  1. 首创 AI 代理经济闭环:首个专为 AI 代理设计的支付层协议,实现机器对机器(M2M)价值交换的原子化结算
  2. 双网络冗余设计:同时支持 Base(100% 可靠性)和 Solana(75% 成功率,含重试机制),用户可按场景选择
  3. 无 Gas 支付体验:Base 网络采用 EIP-3009 TransferWithAuthorization,支付方无需支付 Gas,由 facilitator 代付
  4. 信用点系统:预付费模式消除区块链确认延迟,适合高频调用场景
  5. 开源可审计:MIT 许可证,代码完全公开,依赖 eth-account、web3 等成熟库

潜在局限

  1. Solana 可靠性问题:官方文档明确标注 Solana 支付成功率约 75%,源于 facilitator 的 fee payer 基础设施缺陷,生产环境建议优先使用 Base
  2. 中心化依赖:核心功能依赖 x402layer.cc 官方 API,若服务中断将影响全部操作
  3. 初期部署成本:创建端点需 $5 一次性费用,对小规模实验形成门槛
  4. 私钥管理风险:所有支付操作需暴露私钥至环境变量,虽为功能必需,但增加了安全运维复杂度

适合人群

  • 需要为 AI 服务建立商业化 API 的开发者
  • 希望代理自主购买外部数据/能力的 AI 系统架构师
  • 探索 M2M 经济和代理互操作性的 Web3 研究者
  • 已有 USDC 持仓且熟悉 EVM/Solana 生态的加密原生用户

常规风险

风险类型 等级 说明
资金损失 中 私钥泄露或错误操作可能导致 USDC 被盗,建议小额专用钱包
服务可用性 中 依赖第三方 API 和区块链网络,存在不可控中断可能
价格波动 低 USDC 为稳定币,但极端市场条件下存在脱锚风险
合规风险 中高 加密货币支付可能触发当地监管要求,企业用户需评估

关键安全提示:务必使用专用钱包,限制余额;定期轮换私钥;生产环境建议使用硬件签名或 MPC 方案替代纯环境变量存储。

技能正文


name: x402-layer version: 1.0.1 description: | x402 Singularity Layer - Enable AI agents to deploy monetized API endpoints, consume paid services via USDC payments, manage credits, and participate in a self-sustaining agent economy. Supports Base and Solana networks. metadata: clawdbot: emoji: "⚡" os: - linux - darwin allowed-tools:

  • Read
  • Write
  • Edit
  • Bash
  • WebFetch

x402 Singularity Layer

x402 is a Web3 payment layer enabling AI agents to:

  • 💰 Pay for API access using USDC
  • 🚀 Deploy monetized endpoints
  • 🔍 Discover services via marketplace
  • 📊 Manage endpoints and credits

Networks: Base (EVM) • Solana
Currency: USDC
Protocol: HTTP 402 Payment Required


Quick Start

1. Install Dependencies

pip install -r {baseDir}/requirements.txt

2. Set Up Wallet

# For Base (EVM)
export PRIVATE_KEY="0x..."
export WALLET_ADDRESS="0x..."

# For Solana (optional)
export SOLANA_SECRET_KEY="[1,2,3,...]"  # JSON array

Scripts Overview

🛒 CONSUMER MODE (Buying Services)

Script Purpose
pay_base.py Pay for endpoint on Base network
pay_solana.py Pay for endpoint on Solana network
consume_credits.py Use pre-purchased credits (fast)
consume_product.py Purchase digital products (files)
check_credits.py Check your credit balance
recharge_credits.py Buy credit packs for an endpoint
discover_marketplace.py Browse available services

🏭 PROVIDER MODE (Selling Services)

Script Purpose
create_endpoint.py Deploy new monetized endpoint ($5)
manage_endpoint.py View/update your endpoints
topup_endpoint.py Add credits to YOUR endpoint
list_on_marketplace.py Publish endpoint publicly

Consumer Flows

A. Pay-Per-Request (Recommended)

# Pay with Base (EVM) - 100% reliable
python {baseDir}/scripts/pay_base.py https://api.x402layer.cc/e/weather-data

# Pay with Solana - includes retry logic
python {baseDir}/scripts/pay_solana.py https://api.x402layer.cc/e/weather-data

B. Credit-Based Access (Fastest)

Pre-purchase credits for instant access without blockchain latency:

# Check your balance
python {baseDir}/scripts/check_credits.py weather-data

# Buy credits (consumer purchasing credits)
python {baseDir}/scripts/recharge_credits.py weather-data pack_100

# Use credits for instant access
python {baseDir}/scripts/consume_credits.py https://api.x402layer.cc/e/weather-data

C. Discover Services

# Browse all services
python {baseDir}/scripts/discover_marketplace.py

# Search by keyword
python {baseDir}/scripts/discover_marketplace.py search weather

Provider Flows

A. Create Endpoint ($5 one-time)

Deploy your own monetized API:

python {baseDir}/scripts/create_endpoint.py my-api "My AI Service" https://api.example.com 0.01

Includes 20,000 test credits.

B. Manage Your Endpoint

# List your endpoints
python {baseDir}/scripts/manage_endpoint.py list

# View stats
python {baseDir}/scripts/manage_endpoint.py stats my-api

# Update price
python {baseDir}/scripts/manage_endpoint.py update my-api --price 0.02

C. Top Up YOUR Endpoint (Provider)

Add credits to maintain your endpoint's balance:

python {baseDir}/scripts/topup_endpoint.py my-api 10  # Add $10 worth

Note: This is different from recharge_credits.py which is for CONSUMERS.

D. List on Marketplace

Make your endpoint publicly discoverable:

python {baseDir}/scripts/list_on_marketplace.py my-api --category ai --description "AI-powered analysis"

Payment Technical Details

Base (EVM) - EIP-712 Signatures

Uses USDC TransferWithAuthorization (EIP-3009):

  • Gasless for payer
  • Facilitator settles on-chain
  • 100% reliable

Solana - Versioned Transactions

Uses VersionedTransaction with MessageV0:

  • Facilitator pays gas (from extra.feePayer)
  • SPL Token TransferChecked instruction
  • ~75% success rate (retry logic included)

Environment Reference

Variable Required For Description
PRIVATE_KEY Base payments EVM private key (0x...)
WALLET_ADDRESS All operations Your wallet address
SOLANA_SECRET_KEY Solana payments JSON array of bytes

API Base URL

  • Endpoints: https://api.x402layer.cc/e/{slug}
  • Marketplace: https://api.x402layer.cc/api/marketplace
  • Credits: https://api.x402layer.cc/api/credits/*
  • Agent API: https://api.x402layer.cc/agent/*

Resources


Known Issues

⚠️ Solana payments have ~75% success rate due to facilitator-side fee payer infrastructure issue. Retry logic is included in pay_solana.py. Base (EVM) payments are 100% reliable and recommended for production.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

payapiautomationbackendblockchaincryptocurrencyfinance-accountingoperations

同类 Skill