运行时依赖
无特殊依赖
安装命令
点击复制官方npx clawhub@latest install agentpmt-no-account-agentaddress-x402
镜像加速npx clawhub@latest install agentpmt-no-account-agentaddress-x402 --registry https://cn.longxiaskill.com镜像同步中
本土化适配说明
Agentpmt No Account Agentaddress X402 — 代理付款无账户 代理地址 X402 安装说明: 安装命令:["openclaw skills install agentpmt-no-account-agentaddress-x402"]
技能文档
无需账户使用AgentPMT:AgentAddress和x402 当代理没有AgentPMT账户Bearer Token并需要使用AgentAddress或x402支付工具时,请使用此技能。
此路径适用于需要以下之一的自主代理:
- 已经具有AgentPMT积分的AgentAddress。
- 可以完成x402支付的加密货币钱包。
要求
- pip install requests eth-account
- 将私钥、助记符、签名、支付头和会话随机数存储在密钥管理器中。不要将它们放在提示或日志中。
创建或加载AgentAddress 创建AgentAddress钱包:
import requests
response = requests.post("https://www.agentpmt.com/api/external/agentaddress", timeout=30)
response.raise_for_status()
wallet = response.json()
wallet_address = wallet["evmAddress"].lower()
private_key = wallet["evmPrivateKey"]
如果您已经有一个AgentAddress,请从您的密钥存储中加载其钱包地址和私钥。发现工具
tools_response = requests.get("https://www.agentpmt.com/api/external/tools", timeout=30)
tools_response.raise_for_status()
tools = tools_response.json()
使用特定产品的技能获取产品slug、操作slug、模式和示例参数。已签名的信用流程 当AgentAddress已经具有AgentPMT积分时,请使用此方法。 创建会话随机数:
session_response = requests.post("https://www.agentpmt.com/api/external/auth/session", json={ "wallet_address": wallet_address, }, timeout=30)
session_response.raise_for_status()
session_nonce = session_response.json()["session_nonce"]
规范化操作参数并签名请求:
import hashlib
import json
from eth_account import Account
from eth_account.messages import encode_defunct
product_slug = ""
action_slug = ""
request_path = f"/external/tools/{product_slug}/actions/{action_slug}/invoke"
parameters = {}
canonical = json.dumps(parameters, sort_keys=True, separators=(",", ":"))
payload_hash = hashlib.sha256(canonical.encode("utf-8")).hexdigest()
request_id = "unique-tool-request-id"
message = "\n".join([
"agentpmt-external",
f"wallet:{wallet_address.lower()}",
f"session:{session_nonce}",
f"request:{request_id}",
"method:POST",
f"path:{request_path}",
f"payload:{payload_hash}",
])
signature = Account.sign_message(
encode_defunct(text=message),
private_key=private_key,
).signature.hex()
调用工具:
invoke_url = f"https://www.agentpmt.com/api/external/tools/{product_slug}/actions/{action_slug}/invoke"
response = requests.post(invoke_url, json={
"wallet_address": wallet_address,
"session_nonce": session_nonce,
"request_id": request_id,
"signature": signature,
"parameters": parameters,
}, timeout=120)
response.raise_for_status()
直接x402流程
当代理具有一个已资助的x402功能钱包并希望在工具操作URL处支付时,请使用此方法。直接x402仅在目标供应商产品启用x402时可用。
工具URL与已签名的信用调用中使用的规范操作URL相同:
POST https://www.agentpmt.com/api/external/tools/{productSlug}/actions/{actionSlug}/invoke
在使用x402支付时,不要包含已签名的信用字段(wallet_address、session_nonce、request_id、signature)。仅在JSON正文中发送操作参数,并在支付重试时发送x402支付头。
第一次请求返回402 Payment Required,带有规范的x402挑战。响应正文为JSON,PAYMENT-REQUIRED头包含相同的挑战base64编码。
选择accepts[]中的一个条目并签名该确切要求:
import base64
import json
import secrets
import time
import requests
from eth_account import Account
product_slug = ""
action_slug = ""
invoke_url = f"https://www.agentpmt.com/api/external/tools/{product_slug}/actions/{action_slug}/invoke"
x402_private_key = "<0x-funded-wallet-private-key>"
x402_account = Account.from_key(x402_private_key)
payer_wallet = x402_account.address.lower()
parameters = {
# 操作特定输入字段在此处
}
first = requests.post(invoke_url, json=parameters, timeout=120)
if first.status_code != 402:
first.raise_for_status()
result = first.json()
else:
payment_required = first.json()
accepted = payment_required["accepts"][0]
chain_id = int(accepted["network"].split(":")[1])
valid_before = str(int(time.time()) + min(240, int(accepted.get("maxTimeoutSeconds", 300))))
authorization = {
"from": payer_wallet,
"to": accepted["payTo"].lower(),
"value": str(accepted["amount"]),
"validAfter": "0",
"validBefore": valid_before,
"nonce": "0x" + secrets.token_hex(32),
}
signed = Account.sign_typed_data(