x402 Payment Protocol for TRON Agents
Invoke x402-enabled AI agent endpoints with automatic USDT micropayments on TRON.
Quick Start
Option 1: Run Pre-built (Recommended for Agents)
The skill is pre-bundled into a single file. No installation required.
CODEBLOCK0
Option 2: Development
CODEBLOCK1
Tool Reference
- - Wallet: A TRON private key must be available. The skill automatically looks for it in:
1.
TRON_PRIVATE_KEY environment variable.
2.
~/.mcporter/mcporter.json (AIBank standard configuration).
3.
x402-config.json in the current directory.
4.
~/.x402-config.json in the home directory.
- - USDT on TRON: Wallet needs USDT and some TRX for gas.
Tool Reference
x402troninvoke
Invokes an HTTP endpoint. If payment is required (402), it automatically:
- 1. Negotiates payment requirements.
- Checks USDT allowance. If insufficient, it performs an infinite approval (MAX_UINT256) to minimize future transactions.
- Signs the payment permit (EIP-712).
- Retries the request with the payment signature.
| Parameter | Type | Required | Description |
|---|
| INLINECODE4 | string | Yes | Full URL to invoke |
| INLINECODE5 |
string | No | HTTP method (GET, POST, etc.) Default: GET |
|
body | object | No | JSON body for the request |
|
network | string | No |
mainnet,
nile,
shasta (Default:
nile) |
Example: Chat with Agent
``tool:x402_tron_invoke
url: https://api.example.com/chat
method: POST
body: {"prompt": "Tell me a joke"}
CODEBLOCK2 tool:x402_tron_invoke
url: https://api.example.com/.well-known/agent.json
method: GET
`
---
## Security Rules for Agents
- **No Private Key Output**: The Agent MUST NOT print, echo, or output the TRONPRIVATEKEY or any other signing secret to the dialogue context.
- **Internal Loading Only**: The Agent should rely on the skill or underlying scripts to load the key internally.
- **No Export Commands**: The Agent MUST NOT execute shell commands that contain the private key as a literal string (e.g., export TRONPRIVATEKEY=...).
- **Sanitized Logs**: Ensure that logs or error messages do not leak the key.
## Troubleshooting
### "Private key not found"
Ensure the TRONPRIVATEKEY environment variable is set or a valid x402-config.json exists in the expected locations.
**Agent Note**: If this error occurs, simply inform the user that the environment is not configured. DO NOT attempt to search for or read private keys from files yourself.
### "Insufficient Allowance"
The tool will attempt to broadcast an **infinite approve** transaction. This requires TRX for gas. Ensure your wallet has TRX.
### "Transaction Failed"
Check if you have enough USDT and TRX.
---
## Binary and Image Handling
If the endpoint returns an image (Content-Type: image/*) or binary data (application/octet-stream):
1. The data is automatically saved to a temporary file (e.g., /tmp/x402image... or /tmp/x402binary...).
2. The tool returns a JSON object with:
- filepath: Path to the temporary file.
- contenttype: The MIME type of the content.
- bytes: File size in bytes.
3. **Important**: The Agent is responsible for deleting the temporary file after it has been used or processed.
---
## Network Reference
| Network | Chain ID | CAIP-2 | USDT Contract |
|---------|----------|--------|---------------|
| TRON Mainnet | 0x2b6653dc | eip155:728126428, tron:mainnet | TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t |
| TRON Nile | 0xcd8690dc | eip155:3448148188, tron:nile | TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf |
| TRON Shasta | 0x94a9059e | eip155:2494104990, tron:shasta` | - |
TRON 代理的 x402 支付协议
在 TRON 上通过自动 USDT 微支付调用支持 x402 的 AI 代理端点。
快速开始
选项 1:运行预构建版本(推荐用于代理)
该技能已预打包为单个文件。无需安装。
bash
node dist/index.js --url
[options]
选项 2:开发模式
bash
npm install
npm start -- --url
工具参考
- - 钱包:必须提供 TRON 私钥。该技能会自动在以下位置查找:
1. TRONPRIVATEKEY 环境变量。
2. ~/.mcporter/mcporter.json(AIBank 标准配置)。
3. 当前目录下的 x402-config.json。
4. 主目录下的 ~/.x402-config.json。
- - TRON 上的 USDT:钱包需要持有 USDT 和一些用于支付 Gas 费的 TRX。
工具参考
x402troninvoke
调用 HTTP 端点。如果需要支付(402),它会自动:
- 1. 协商支付要求。
- 检查 USDT 授权额度。如果不足,则执行无限授权(MAX_UINT256)以最小化未来交易次数。
- 签署支付许可(EIP-712)。
- 使用支付签名重试请求。
| 参数 | 类型 | 必填 | 描述 |
|---|
| url | 字符串 | 是 | 要调用的完整 URL |
| method |
字符串 | 否 | HTTP 方法(GET、POST 等)。默认值:GET |
| body | 对象 | 否 | 请求的 JSON 主体 |
| network | 字符串 | 否 | mainnet、nile、shasta(默认值:nile) |
示例:与代理聊天
tool:x402troninvoke
url: https://api.example.com/chat
method: POST
body: {prompt: 给我讲个笑话}
代理发现
您可以通过查看代理的清单文件来发现可用的端点及其定价。
获取代理清单
tool:x402troninvoke
url: https://api.example.com/.well-known/agent.json
method: GET
代理安全规则
- - 禁止输出私钥:代理不得打印、回显或输出 TRONPRIVATEKEY 或任何其他签名密钥到对话上下文中。
- 仅限内部加载:代理应依赖技能或底层脚本在内部加载密钥。
- 禁止导出命令:代理不得执行包含私钥字面字符串的 shell 命令(例如 export TRONPRIVATEKEY=...)。
- 清理日志:确保日志或错误消息不会泄露密钥。
故障排除
未找到私钥
请确保已设置 TRONPRIVATEKEY 环境变量,或在预期位置存在有效的 x402-config.json 文件。
代理注意事项:如果出现此错误,只需告知用户环境未配置。请勿自行尝试从文件中搜索或读取私钥。
授权额度不足
该工具将尝试广播一笔无限授权交易。这需要 TRX 作为 Gas 费。请确保您的钱包中有 TRX。
交易失败
请检查您是否有足够的 USDT 和 TRX。
二进制和图像处理
如果端点返回图像(Content-Type: image/*)或二进制数据(application/octet-stream):
- 1. 数据会自动保存到临时文件(例如 /tmp/x402image... 或 /tmp/x402binary...)。
- 该工具返回一个包含以下内容的 JSON 对象:
- file_path:临时文件的路径。
- content_type:内容的 MIME 类型。
- bytes:文件大小(以字节为单位)。
- 3. 重要提示:代理负责在使用或处理完临时文件后将其删除。
网络参考
| 网络 | 链 ID | CAIP-2 | USDT 合约地址 |
|---|
| TRON 主网 | 0x2b6653dc | eip155:728126428, tron:mainnet | TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t |
| TRON Nile |
0xcd8690dc | eip155:3448148188, tron:nile | TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf |
| TRON Shasta | 0x94a9059e | eip155:2494104990, tron:shasta | - |