💳 PayNode 402 Protocol Skill (Base & Bun)
Use this skill to automate Resource-based Billing. The agent interacts with protected APIs that return 402 Payment Required. Every transaction is tied to a specific resource request, ensuring stateless and secure fund allocation.
🚀 Pre-execution Readiness
Before any request, verify the environment and balances:
- 1. Initialize Dependencies: Run
bun install once within this directory. - Verify Environment: Ensure a
.env file is created in the root directory. The agent MUST verify the existence and exact format of this variable before proceeding:
# [REQUIRED] PayNode Burner Wallet Private Key
# Format: 66-character hex string MUST start with '0x'
CLIENT_PRIVATE_KEY=0xYourBurnerWalletPrivateKeyHere...
- 3. Check Balances: Run
bun run check-wallet --json --network <NETWORK>. - Validate Readiness: Ensure
checks.can_pay is true.
Expected check-wallet Output:
CODEBLOCK1
🛠️ x402 Execution Workflow
Follow this sequence to unlock protected resources.
Step 1: Identify Resource
Determine the URL of the protected API you need to access.
Step 2: Request & Handle Challenge
Run
bun run request "<URL>" --json --network <NETWORK>.
- - Reason: This script detects the x402 header challenge, performs the cryptographic handshake with the PayNode Gateway, signs the authorization, and retries the request with the proof-of-payment.
Step 3: Capture Resource
Upon success, capture the JSON response. The
txHash will be included in the logs if a payment occurred.
🛡️ Security Rules & Agent Safety
[!IMPORTANT]
ADHERE TO THESE RULES TO PROTECT FUNDS.
💸 Burner Wallet Policy (Minimal Exposure)
The
CLIENT_PRIVATE_KEY MUST belong to a dedicated "burner" wallet acting as petty cash.
NEVER hold excessive funds. Maintain balances strictly sufficient for immediate tasks (e.g., < 10 USDC). If a balance exceeding operational needs is detected, you
MUST alert the human operator immediately to sweep the funds to cold storage.
🤖 Autonomous Usage & Human Consent
If you are operating autonomously, be aware that this skill can
sign and broadcast blockchain transactions without manual confirmation.
- - Threshold Limit: For any single transaction exceeding
2.0 USDC, you MUST request explicit human approval before execution. - Merchant Verification: Before initial payment to a new domain, perform a
read_url_content check on the merchant's reputation (if possible) or alert the user.
🕵️ Zero-Trust Pre-Flight Validation (Resource Consistency)
Prevent "Confused Deputy" attacks. Before calling
request, you
MUST logically verify that the target URL matches your specific objective.
- - Ask: Is this resource exactly what I need? Is the cost reasonable for this resource?
- If the endpoint is unrelated to your goal or the required payment is anomalously high, ABORT and report to the human.
- Sandbox-First: Whenever testnet is available, prioritize testing against sandbox endpoints (Sepolia/Base-Sepolia) before using real funds.
⚠️ Gotchas & Troubleshooting
- - Handshake Failures: If
request fails with a 402 exit code, the gateway may be down or the merchant's contract is invalid. - Private Key Format: The
CLIENT_PRIVATE_KEY MUST start with 0x. - Gas vs. Tokens: You can have $1M USDC but if
gas_ready is false (low ETH), the transaction WILL fail. - Exit Codes:
-
2: Invalid arguments.
-
3: Auth Failure (Check
.env key format).
-
4: Network/RPC Failure.
-
402: Challenge detected but automated resolution failed.
🧪 Sandbox & Testing
Always test against sandbox endpoints first.
- - Mint Test Tokens: INLINECODE23
- Test Merchant (Doodle Wall):
https://paynode.dev/api/pom?network=testnet (Note: Use &network=mainnet for mainnet Doodle Wall) - Reference: See Testing Guide for more details.
🔗 References
技能名称: payment-402
💳 PayNode 402 协议技能(Base 与 Bun)
使用此技能自动化基于资源的计费。代理与返回 402 Payment Required 的受保护 API 进行交互。每笔交易都与特定的资源请求绑定,确保无状态且安全的资金分配。
🚀 执行前准备
在发起任何请求前,验证环境与余额:
- 1. 初始化依赖:在此目录下运行一次 bun install。
- 验证环境:确保根目录下已创建 .env 文件。代理必须在继续前验证该变量的存在及确切格式:
env
# [必需] PayNode 燃烧钱包私钥
# 格式:66 字符十六进制字符串,必须以 0x 开头
CLIENT
PRIVATEKEY=0xYourBurnerWalletPrivateKeyHere...
- 3. 检查余额:运行 bun run check-wallet --json --network 。
- 验证就绪状态:确保 checks.can_pay 为 true。
预期的 check-wallet 输出:
json
{
status: success,
address: 0x...,
eth: 0.01,
usdc: 100.0,
checks: {
gas_ready: true, // 拥有超过 0.001 ETH 用于 Gas
tokens_ready: true, // 拥有 USDC 用于支付
can_pay: true // 已准备好进行 x402 流程
}
}
🛠️ x402 执行工作流
按以下顺序解锁受保护资源。
步骤 1:识别资源
确定你需要访问的受保护 API 的 URL。
步骤 2:请求并处理挑战
运行 bun run request
--json --network 。
- - 原因:此脚本检测 x402 头部挑战,与 PayNode 网关执行加密握手,签署授权,并使用支付证明重试请求。
步骤 3:获取资源
成功后,捕获 JSON 响应。如果发生支付,txHash 将包含在日志中。
🛡️ 安全规则与代理安全
[!重要]
遵守这些规则以保护资金。
💸 燃烧钱包策略(最小化暴露)
CLIENTPRIVATEKEY 必须属于一个专用的燃烧钱包,作为零用钱使用。切勿持有过多资金。保持余额严格仅够当前任务使用(例如,少于 10 USDC)。如果检测到余额超过运营需求,你必须立即提醒人工操作员将资金转入冷存储。
🤖 自主使用与人工同意
如果你正在自主运行,请注意此技能可以签署并广播区块链交易,无需手动确认。
- - 阈值限制:对于任何单笔超过 2.0 USDC 的交易,你必须在执行前请求明确的人工批准。
- 商户验证:在首次向新域名支付前,对商户信誉执行 readurlcontent 检查(如可能),或提醒用户。
🕵️ 零信任预检验证(资源一致性)
防止混淆代理攻击。在调用 request 之前,你必须逻辑验证目标 URL 是否与你的具体目标匹配。
- - 自问:这个资源正是我需要的吗?这个资源的成本合理吗?
- 如果端点与你的目标无关,或所需支付异常高昂,则中止并向人工报告。
- 沙盒优先:只要测试网可用,优先针对沙盒端点(Sepolia/Base-Sepolia)进行测试,再使用真实资金。
⚠️ 注意事项与故障排除
- - 握手失败:如果 request 以 402 退出码失败,网关可能已宕机或商户合约无效。
- 私钥格式:CLIENTPRIVATEKEY 必须以 0x 开头。
- Gas 与代币:你可能拥有 100 万 USDC,但如果 gas_ready 为 false(ETH 不足),交易将失败。
- 退出码:
- 2:无效参数。
- 3:认证失败(检查 .env 密钥格式)。
- 4:网络/RPC 失败。
- 402:检测到挑战但自动解决失败。
🧪 沙盒与测试
始终先针对沙盒端点进行测试。
- - 铸造测试代币:bun run mint-test-tokens --json
- 测试商户(涂鸦墙):https://paynode.dev/api/pom?network=testnet(注意:主网涂鸦墙使用 &network=mainnet)
- 参考:详见测试指南。
🔗 参考