Agent Fuel — Autonomous Payment & Gas Management
Keep your agent running by automatically managing wallet balances, topping up via MoonPay, and paying for x402-enabled APIs.
Prerequisites
- 1. MoonPay CLI installed and authenticated:
CODEBLOCK0
- 2. A funded wallet (can be created via
mp wallet create)
Quick Start
Check Balance
CODEBLOCK1
Auto Top-Up When Low
When the agent detects low balance (configurable threshold), trigger:
CODEBLOCK2
Swap Tokens
CODEBLOCK3
x402 Payments
For APIs that return HTTP 402, the agent should:
- 1. Parse the
PAYMENT-REQUIRED header for amount and payment address - Sign the payment using the agent wallet
- Retry the request with
PAYMENT-SIGNATURE header - Log the transaction
Balance Monitoring
The agent should periodically check balance and act:
CODEBLOCK4
Configuration
Store in ~/clawd/.secrets/agent-fuel.json:
CODEBLOCK5
Safety Rules
- - NEVER exceed
maxDailySpend without human approval - ALWAYS log transactions with reason
- ALERT human when balance drops below INLINECODE5
- PAUSE spending if 3+ top-ups in 1 hour (possible loop)
MoonPay CLI Reference
| Command | Description |
|---|
| INLINECODE6 | Check all wallet balances |
| INLINECODE7 |
Create new wallet |
|
mp buy --amount N --currency TOKEN | Buy crypto with fiat |
|
mp swap --from X --to Y --amount N | Swap tokens |
|
mp send --to ADDR --amount N --currency TOKEN | Send tokens |
|
mp wallet history | Transaction history |
|
mp mcp | Start MCP server for agent integration |
Agent Fuel — 自主支付与燃料管理
通过自动管理钱包余额、通过MoonPay充值以及为支持x402的API支付,保持您的代理持续运行。
前置条件
- 1. 安装并认证MoonPay CLI:
bash
npm install -g @moonpay/cli
mp login
- 2. 一个已充值的钱包(可通过 mp wallet create 创建)
快速开始
检查余额
bash
mp wallet balance
余额不足时自动充值
当代理检测到余额不足时(阈值可配置),触发:
bash
mp buy --amount 20 --currency USDC --chain base
代币兑换
bash
mp swap --from ETH --to USDC --amount 0.01 --chain base
x402支付
对于返回HTTP 402的API,代理应:
- 1. 解析 PAYMENT-REQUIRED 头中的金额和支付地址
- 使用代理钱包签署支付
- 使用 PAYMENT-SIGNATURE 头重试请求
- 记录交易
余额监控
代理应定期检查余额并执行操作:
如果 余额 < 最低余额:
如果 当日已花费 < 最高日花费:
执行 mp buy --amount {充值金额} --currency USDC
通知用户 ⛽ 自动充值:${充值金额} USDC
否则:
通知用户 ⚠️ 已达日消费上限。需要手动充值。
配置
存储在 ~/clawd/.secrets/agent-fuel.json:
json
{
chain: base,
currency: USDC,
minBalance: 5.0,
topUpAmount: 20.0,
maxDailySpend: 100.0,
alertThreshold: 2.0,
x402Enabled: true,
x402MaxPerRequest: 0.10
}
安全规则
- - 未经用户批准,绝不超过 maxDailySpend
- 始终记录交易并注明原因
- 当余额低于 alertThreshold 时提醒用户
- 如果1小时内充值3次以上则暂停支出(可能陷入循环)
MoonPay CLI参考
| 命令 | 描述 |
|---|
| mp wallet balance | 检查所有钱包余额 |
| mp wallet create |
创建新钱包 |
| mp buy --amount N --currency TOKEN | 用法币购买加密货币 |
| mp swap --from X --to Y --amount N | 兑换代币 |
| mp send --to ADDR --amount N --currency TOKEN | 发送代币 |
| mp wallet history | 交易历史 |
| mp mcp | 启动MCP服务器用于代理集成 |