网淘吧来吧,欢迎您!

x402 Singularity Layer技能使用说明

2026-03-31 新闻来源:网淘吧 围观:15
电脑广告
手机广告

x402 奇点层

x402 是一个 Web3 支付层,人类和智能体可以在此出售和消费 API、产品和服务积分。 本技能涵盖了奇点层的完整生命周期:

  • 支付/消费服务
  • 创建/管理/列出端点
  • 将自定义支付流程集成到应用或平台中
  • 接收并验证 Webhook 支付事件
  • 注册智能体并提交链上信誉反馈
  • 可选择使用 Singularity MCP 进行所有者范围内的仪表板和控制平面操作

网络:Base、Ethereum、Polygon、BSC、Monad、Solana
货币:USDC
协议:HTTP 402 需要付款

x402 Singularity Layer


意图路由器

请先使用此路由,然后加载相关的参考文档。

用户意图主要路径参考
将加密货币支付集成到应用/平台中create_endpoint.py,manage_webhook.py,verify_webhook_payment.py,consume_product.py,recharge_credits.pyreferences/payments-integration.md,references/webhooks-verification.md,references/agentic-endpoints.md
支付/消费端点或产品pay_base.py,pay_solana.py,consume_credits.py,consume_product.pyreferences/pay-per-request.md,references/credit-based.md,references/agentkit-benefits.md
发现/搜索市场discover_marketplace.pyreferences/marketplace.md,references/agentkit-benefits.md
创建/编辑/列出端点create_endpoint.py,manage_endpoint.py,list_on_marketplace.py,topup_endpoint.pyreferences/agentic-endpoints.md,references/marketplace.md,references/agentkit-benefits.md
通过个人访问令牌支持的访问来管理仪表板/平台控制平面Singularity MCP工具,例如list_my_endpoints,update_endpoint列出我的产品更新产品设置网络钩子移除网络钩子请求端点创建支付references/mcp-control-plane.mdreferences/agentic-endpoints.mdreferences/marketplace.md配置/验证网络钩子manage_webhook.pyverify_webhook_payment.pyreferences/webhooks-verification.md注册/发现/管理/评价代理 (ERC-8004/Solana-8004)register_agent.pylist_agents.py
Configure/verify webhooksmanage_webhook.py,verify_webhook_payment.pyreferences/webhooks-verification.md
Register/discover/manage/rate agents (ERC-8004/Solana-8004)register_agent.py,list_agents.py,列出我的端点.py,更新代理.py,提交反馈.py参考/代理注册-声誉.md
人工支持代理钱包优势(World AgentKit)支付基础.py,发现市场.py参考/agentkit-优势.md
支持与买家/卖家消息传递支持认证.py,支持线程.py,xmtp_支持.mjs参考/xmtp-支持.md

快速入门

1) 安装技能依赖项

pip install -r {baseDir}/requirements.txt

2) 选择钱包模式

选项A:私钥

export PRIVATE_KEY="0x..."
export WALLET_ADDRESS="0x..."
# Solana optional
export SOLANA_SECRET_KEY="base58-or-[1,2,3,...]"

选项B:Coinbase AWAL

# Install Coinbase AWAL skill (shortcut)
npx skills add coinbase/agentic-wallet-skills
export X402_USE_AWAL=1

使用私钥模式进行 ERC-8004 钱包优先注册。AWAL 在 x402 支付流程中仍然有用。

3) 可选仪表板 / MCP 模式

如果用户提供了仪表板 PAT,代理也可以使用 Singularity MCP 执行所有者作用域的账户操作:

export SINGULARITY_PAT="sgl_pat_..."

当任务涉及以下内容时,使用 MCP:

  • 列出仪表板用户拥有的所有端点或产品
  • 更新端点或产品设置
  • 设置或移除 Webhook
  • 以所有者作用域的方式请求创建端点或充值支付挑战

保留直接脚本用于:

  • 实际请求支付和本地签名
  • AWAL 驱动的支付/发现流程
  • 支持和 XMTP 流程
  • 钱包优先的 ERC-8004 / Solana-8004 注册和更新

安全说明:脚本仅读取显式声明的进程环境变量。.env文件不会自动加载。 安装说明:安装时不需要全局设置任何秘密环境变量。只需根据您正在使用的操作手册,设置所需的那部分变量。


脚本清单

消费者

脚本用途
pay_base.pyBase链上的支付端点,包含可选的AgentKit权益流程
pay_solana.pySolana链上的支付端点
consume_credits.py使用积分进行消费
consume_product.py购买数字产品/文件
check_credits.py查询积分余额
recharge_credits.py购买端点积分套餐
discover_marketplace.py浏览/搜索市场并查看AgentKit权益
support_auth.py为支持API验证钱包身份
support_threads.py检查支持资格,开启/列出/显示/关闭/重新开启支持工单
xmtp_support.mjs收发XMTP支持消息以处理支持线程
awal_cli.py运行AWAL认证/支付/发现命令

提供方

脚本用途
create_endpoint.py部署端点(一次性$1,包含4,000积分)
manage_endpoint.py列出/更新端点设置
topup_endpoint.py为提供方端点充值积分
list_on_marketplace.py上架/下架/更新市场列表
manage_webhook.py设置/移除/检查端点webhook URL
verify_webhook_payment.py验证webhook签名及收据真实性(使用PyJWT/JWKS)

智能体注册与信誉系统

脚本用途
register_agent.py注册支持镜像/版本/标签和端点绑定的 ERC-8004/Solana-8004 代理
list_agents.py列出由配置的钱包或关联的仪表板用户拥有的 ERC-8004 代理
list_my_endpoints.py列出可链接到 ERC-8004 代理的平台端点
update_agent.py更新现有的 ERC-8004/Solana-8004 代理元数据、可见性和端点绑定
submit_feedback.py提交链上声誉反馈

核心安全要求

在源站进行 API 密钥验证(强制要求)

当 x402 将流量代理到您的源站时,请验证:

x-api-key: <YOUR_API_KEY>

当缺失或无效时拒绝请求。

积分经济体系(提供方侧)

  • 端点创建:一次性 1 美元
  • 初始积分:4,000
  • 充值汇率:每 1 美元兑换 500 积分
  • 消耗:每次请求 1 积分
  • 如果积分降至 0,端点将停止服务,直到重新充值

快速操作指南

A) 将支付集成到您的应用中

# 1. Create or reuse a paid endpoint
python {baseDir}/scripts/create_endpoint.py my-api "My API" https://api.example.com 0.01

# 2. Add server-side fulfillment
python {baseDir}/scripts/manage_webhook.py set my-api https://my-server.com/webhook

# 3. Verify webhook signatures and payment receipts server-side
python {baseDir}/scripts/verify_webhook_payment.py \
  --body-file ./webhook.json \
  --signature 't=1700000000,v1=<hex>' \
  --secret '<YOUR_SIGNING_SECRET>' \
  --required-source-slug my-api \
  --require-receipt

B) 支付与消耗

python {baseDir}/scripts/pay_base.py https://api.x402layer.cc/e/weather-data
python {baseDir}/scripts/pay_base.py https://api.x402layer.cc/e/weather-data --agentkit auto
python {baseDir}/scripts/pay_solana.py https://api.x402layer.cc/e/weather-data
python {baseDir}/scripts/consume_credits.py https://api.x402layer.cc/e/weather-data

C) 发现/搜索市场

python {baseDir}/scripts/discover_marketplace.py
python {baseDir}/scripts/discover_marketplace.py search weather
python {baseDir}/scripts/discover_marketplace.py details weather-api

D) 创建和管理端点

python {baseDir}/scripts/create_endpoint.py my-api "My API" https://api.example.com 0.01
python {baseDir}/scripts/manage_endpoint.py list
python {baseDir}/scripts/manage_endpoint.py update my-api --price 0.02
python {baseDir}/scripts/topup_endpoint.py my-api 10

E) 在市场列表/更新

python {baseDir}/scripts/list_on_marketplace.py my-api \
  --category ai \
  --description "AI-powered analysis" \
  --logo https://example.com/logo.png \
  --banner https://example.com/banner.jpg

F) Webhook 设置与真实性验证

python {baseDir}/scripts/manage_webhook.py set my-api https://my-server.com/webhook
python {baseDir}/scripts/manage_webhook.py info my-api
python {baseDir}/scripts/manage_webhook.py remove my-api

Webhook 验证辅助工具:

python {baseDir}/scripts/verify_webhook_payment.py \
  --body-file ./webhook.json \
  --signature 't=1700000000,v1=<hex>' \
  --secret '<YOUR_SIGNING_SECRET>' \
  --required-source-slug my-api \
  --require-receipt

G) World AgentKit 优势

# Inspect whether a listing advertises a verified human-backed agent wallet benefit
python {baseDir}/scripts/discover_marketplace.py details weather-data

# Attempt Base payment with AgentKit if the endpoint advertises a benefit
python {baseDir}/scripts/pay_base.py https://api.x402layer.cc/e/weather-data --agentkit auto

# Require AgentKit qualification instead of silently falling back
python {baseDir}/scripts/pay_base.py https://api.x402layer.cc/e/weather-data --agentkit required

H) XMTP 支持线程

# Authenticate the current wallet for support APIs
python {baseDir}/scripts/support_auth.py login

# Check whether support is available for a listing
python {baseDir}/scripts/support_threads.py eligibility endpoint weather-data

# Open or reuse the support thread
python {baseDir}/scripts/support_threads.py open endpoint weather-data

# Read and send XMTP messages for a support thread
node {baseDir}/scripts/xmtp_support.mjs messages <thread_id>
node {baseDir}/scripts/xmtp_support.mjs send <thread_id> "Need help with this endpoint"

I) MCP 所有者作用域控制平面

# Set a dashboard PAT only for owner-scoped control-plane actions
export SINGULARITY_PAT="sgl_pat_..."

# Then use Singularity MCP for owner inventory/config operations such as:
# - list_my_endpoints
# - update_endpoint
# - list_my_products
# - update_product
# - set_webhook
# - remove_webhook
# - request_endpoint_creation_payment

J) 代理注册 + 声誉

python {baseDir}/scripts/list_my_endpoints.py

python {baseDir}/scripts/register_agent.py \
  "My Agent" \
  "Autonomous service agent" \
  --network baseSepolia \
  --image https://example.com/agent.png \
  --version 1.9.1 \
  --tag finance \
  --tag automation \
  --endpoint-id <ENDPOINT_UUID> \
  --custom-endpoint https://api.example.com/agent

python {baseDir}/scripts/list_agents.py --network baseSepolia

python {baseDir}/scripts/update_agent.py \
  --network baseSepolia \
  --agent-id 123 \
  --version 1.4.1 \
  --tag finance \
  --tag automation \
  --endpoint-id <ENDPOINT_UUID> \
  --public

# The same EVM flow also supports:
#   --network ethereum
#   --network polygon
#   --network bsc
#   --network monad

python {baseDir}/scripts/submit_feedback.py \
  --network base \
  --agent-id 123 \
  --rating 5 \
  --comment "High quality responses"

参考资料

仅加载用户任务所需内容:

  • 参考资料/支付集成.md: 产品 vs 端点 vs 积分的决策指南,以及 webhook/收据履行模式。
  • 参考资料/按请求付费.md: EIP-712/Solana 支付流程和底层签名细节。
  • 参考资料/基于积分的.md: 积分购买 + 消耗行为及示例。
  • 参考资料/市场.md: 搜索/列出/取消列出市场端点。
  • 参考资料/agentkit-权益.md: 发现、获取资格并利用World AgentKit人工支持代理钱包权益进行支付。
  • 参考资料/代理端点.md: 端点创建/充值/状态API行为。
  • 参考资料/webhooks-验证.md: webhook事件、签名验证和收据交叉检查。
  • 参考资料/代理注册表-声誉.md: ERC-8004/Solana-8004注册、发现、管理和反馈规则。
  • 参考资料/xmtp-支持.md: 支持聊天在Studio中的工作原理、需要人工设置的内容以及代理应如何与用户协调。
  • 参考资料/mcp-控制平面.md: 何时使用Singularity MCP、需要哪些PAT作用域,以及哪些所有者作用域的操作应优先使用MCP而非直接脚本。
  • 参考资料/支付签名.md: 确切的签名域/类型/头部负载详细信息。

环境参考

没有单一任务需要用到以下所有变量。请遵循最小权限原则,仅设置当前脚本所需的变量。

通用

变量使用场景备注
WALLET_ADDRESS多数Base/EVM流程主钱包地址
PRIVATE_KEYBase私钥模式、支持认证、XMTP助手EVM签名密钥
X402_USE_AWALAWAL模式设置值1
X402_AUTH_MODE认证方式选择自动私钥awal
X402_PREFER_NETWORK网络选择base,solana
X402_AGENTKIT_MODE可选的 AgentKit 行为关闭,自动,必需
X402_API_BASEAPI 重写默认https://api.x402layer.cc

可选的 MCP 控制平面

变量被...使用备注
SINGULARITY_PATSingularity MCP 所有者范围的管理流程可选的 PAT,格式为sgl_pat_*;安装或正常脚本使用不需要

提供商与市场管理

变量被...使用备注
X_API_KEY端点/webhook/列表管理端点API密钥
API_KEY管理脚本的回退方案可与...互换的回退方案X_API_KEY

Solana

变量使用者备注
SOLANA_SECRET_KEYSolana私钥模式base58格式密钥或JSON数组字节
SOLANA_WALLET_ADDRESSSolana覆盖和列表辅助功能可选
WALLET_ADDRESS_SECONDARY双链端点模式可选

支持与XMTP

变量使用者备注
支持代理令牌支持线程脚本可选重用先前登录
X402_STUDIO_BASE_URLsupport_auth.py,support_threads.py可选 Studio API 基础覆盖
X402_API_BASE_URL支持线程脚本默认https://api.x402layer.cc
XMTP_ENVxmtp_support.mjs默认生产环境
XMTP_DB_PATHxmtp_support.mjs可选持久化数据库路径覆盖

代理注册和反馈

变量使用者备注
WORKER_FEEDBACK_API_KEYsubmit_feedback.py仅用于信誉反馈写入
BASE_RPC_URL以及其他链的 RPC URLregister_agent.py用于代理注册的可选 RPC 覆盖

API 基础路径

  • 端点:https://api.x402layer.cc/e/{slug}
  • 市场:https://api.x402layer.cc/api/marketplace
  • 积分:https://api.x402layer.cc/api/credits/*
  • 代理路由:https://api.x402layer.cc/agent/*
  • MCP:https://mcp.x402layer.cc/mcp

资源


已知问题

Solana 精确支付流程必须使用费用支付方由挑战返回,并将交易的计算单元限制保持在协调方要求范围内。pay_solana.pysolana_signing.py已为当前 PayAI 支持的流程处理此问题;当你需要最简单的生产路径时,建议优先使用 Base。

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第393720名访客 今日有1篇新文章/评论