DEV Community

Yaqing2023
Yaqing2023

Posted on

MoltsPay:让 AI Agent 自主完成支付的开源协议

🤖 AI Agent 的支付困境

当我们构建 AI Agent 时,一个核心问题浮现:Agent 如何为服务付费?

想象一下:你的 Agent 需要调用一个视频生成 API,费用是 $0.99。传统方案是:

  1. 用户预存余额
  2. Agent 用 API Key 调用
  3. 服务商从余额扣费

这套流程需要人工介入——注册账号、绑卡、充值。对于 Agent-to-Agent 的自动化场景,这完全不可行。

💡 MoltsPay 的解决方案

MoltsPay 是一个基于 x402 协议的开源支付基础设施,让 AI Agent 能够:

  • 🔐 自主管理钱包 - 无需人工干预
  • 💸 即时 USDC 支付 - Base 链上,秒级确认
  • 🔍 自动发现服务 - 通过 .well-known/agent-services.json
  • 完全无 Gas - CDP Facilitator 代付 gas

🚀 快速接入

Node.js

npm install moltspay
npx moltspay init --chain base
npx moltspay pay https://juai8.com/zen7 text-to-video --prompt "一只猫在跳舞"
Enter fullscreen mode Exit fullscreen mode

Python

pip install moltspay
moltspay init --chain base
moltspay pay https://juai8.com/zen7 text-to-video --prompt "一只猫在跳舞"
Enter fullscreen mode Exit fullscreen mode

两个 SDK 的 CLI 命令完全一致!

💻 代码示例

JavaScript

import { MoltsPay } from "moltspay";

const client = new MoltsPay();
const result = await client.pay({
  service: "https://juai8.com/zen7",
  serviceId: "text-to-video",
  params: { prompt: "未来城市的日落" }
});

console.log(result.videoUrl);
Enter fullscreen mode Exit fullscreen mode

Python

from moltspay import MoltsPay

client = MoltsPay()
result = client.pay(
    service="https://juai8.com/zen7",
    service_id="text-to-video",
    params={"prompt": "未来城市的日落"}
)

print(result.video_url)
Enter fullscreen mode Exit fullscreen mode

🛠️ 服务提供商接入

如果你想把自己的 AI 服务变成可被 Agent 发现和购买的商品,只需添加一个 JSON 文件:

// moltspay.services.json
{
  "provider": {
    "name": "My AI Service",
    "wallet": "0xYourWalletAddress"
  },
  "services": [
    {
      "id": "image-gen",
      "name": "AI 图像生成",
      "function": "generateImage",
      "price": 0.50,
      "currency": "USDC"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

然后启动服务:

# Node.js
npx moltspay start ./my-skill --port 8402

# Python
moltspay start ./my-skill --port 8402
Enter fullscreen mode Exit fullscreen mode

你的服务现在可以被任何 Agent 发现和购买了!

🔗 x402 协议

MoltsPay 基于 x402 协议,这是一个 HTTP 原生的支付标准:

  1. Client 请求资源
  2. Server 返回 402 Payment Required + 价格信息
  3. Client 签名支付
  4. Server 验证后返回资源

整个流程在一次 HTTP 请求中完成,无需额外的支付网关。

📊 实际案例:Zen7 视频生成

我们运营的 Zen7 是第一个基于 MoltsPay 的商业服务:

  • 文字生成视频: $0.99/次
  • 图片动画化: $1.49/次
  • 日均交易: 50+ 笔

🌐 生态系统

🎯 下一步

Node.js 开发者:

npm install moltspay && npx moltspay init
Enter fullscreen mode Exit fullscreen mode

Python 开发者:

pip install moltspay && moltspay init
Enter fullscreen mode Exit fullscreen mode

然后体验支付:

moltspay pay https://juai8.com/zen7 text-to-video --prompt "测试"
Enter fullscreen mode Exit fullscreen mode

有问题?欢迎在评论区交流,或加入我们的 Discord


MoltsPay 是开源项目,欢迎贡献代码和反馈。让我们一起构建 Agent 经济的支付基础设施!

Top comments (0)