🚀 快速安装

复制以下命令并运行,立即安装此 Skill:

clawhub install 8004

💡 提示:需要提前安装 clawhub CLI

ERC-8004: 智能体信任协议

ERC-8004 为自主 AI 智能体建立了信任基础设施,使它们能够跨组织边界发现、识别和评估其他智能体。

何时使用

  • 在链上注册 AI 智能体的身份
  • 为 AI 智能体构建声誉系统
  • 在交互前验证智能体身份
  • 查询智能体声誉和反馈
  • 实现基于信任的智能体交互

核心概念

三大注册表

注册表 目的 关键功能
身份注册表 通过 ERC-721 NFT 发现智能体 register(), agentURI()
声誉注册表 反馈和证明 giveFeedback(), getSummary()
验证注册表 验证钩子 自定义验证器

协议栈位置

应用层 (智能体应用、市场)
    ↓
信任层 (ERC-8004) ← 本技能
    ↓
支付层 (x402)
    ↓
通信层 (A2A, MCP)

安装

# JavaScript/TypeScript
npm install @chaoschain/sdk

# Python
pip install chaoschain-sdk

合约地址

Celo 主网

合约 地址
身份注册表 即将推出(2026 年第一季度)
声誉注册表 即将推出(2026 年第一季度)

Celo Sepolia(测试网)

合约 地址
身份注册表 即将推出
声誉注册表 即将推出

智能体注册

1. 创建注册文件

创建描述端点和能力的智能体注册文件:

{
  "type": "Agent",
  "name": "我的 AI 智能体",
  "description": "能力描述",
  "image": "ipfs://Qm...",
  "endpoints": [
    {
      "type": "a2a",
      "url": "https://example.com/.well-known/agent.json"
    },
    {
      "type": "mcp",
      "url": "https://example.com/mcp"
    },
    {
      "type": "wallet",
      "address": "0x...",
      "chainId": 42220
    }
  ],
  "supportedTrust": ["reputation", "validation", "tee"]
}

2. 上传到 IPFS

import { upload } from "@chaoschain/sdk";

const agentMetadata = {
  type: "Agent",
  name: "我的 AI 智能体",
  description: "用于 DeFi 操作的 AI 智能体",
  // ...
};

const agentURI = await upload(agentMetadata);
// 返回: ipfs://QmYourRegistrationFile

3. 注册智能体

import { IdentityRegistry } from '@chaoschain/sdk';
import { createPublicClient, http } from 'viem';
import { celo } from 'viem/chains';

const client = createPublicClient({
  chain: celo,
  transport: http('https://forno.celo.org'),
});

const registry = new IdentityRegistry(client);

// 注册并获取智能体 ID
const tx = await registry.register(agentURI);
const agentId = tx.events.Transfer.returnValues.tokenId;

console.log('智能体注册成功,ID:', agentId);

声誉系统

提供反馈

import { ReputationRegistry } from '@chaoschain/sdk';

const reputation = new ReputationRegistry(client);

await reputation.giveFeedback(
  agentId,           // 要评价的智能体 ID
  85,                // 分数 (0-100)
  0,                 // 小数位数
  'starred',         // 标签1:类别
  '',                // 标签2:可选
  'https://agent.example.com',  // 使用的端点
  'ipfs://QmDetailedFeedback',  // 详细反馈 URI
  feedbackHash       // 反馈内容的 keccak256 哈希
);

常用反馈标签

标签 衡量指标 示例
starred 质量评分 (0-100) 87/100
uptime 端点在线率 % 99.77%
successRate 任务成功率 % 89%
responseTime 响应时间 (毫秒) 560ms
reachable 端点是否可达 true/false

查询声誉

// 获取智能体的所有反馈
const feedback = await reputation.readAllFeedback(agentId);

// 获取聚合摘要
const summary = await reputation.getSummary(agentId);
console.log('平均评分:', summary.averageScore);
console.log('评价总数:', summary.totalFeedback);

信任验证工作流

import { IdentityRegistry, ReputationRegistry } from '@chaoschain/sdk';

async function verifyAndInteract(targetAgentId, minReputation = 70) {
  // 1. 验证身份
  const identity = await identityRegistry.getAgent(targetAgentId);
  if (!identity) {
    throw new Error('智能体未注册');
  }

  // 2. 检查声誉
  const summary = await reputationRegistry.getSummary(targetAgentId);
  if (summary.averageScore < minReputation) {
    throw new Error(`智能体声誉 ${summary.averageScore} 低于阈值 ${minReputation}`);
  }

  // 3. 获取端点
  const agentData = await fetch(identity.agentURI).then(r => r.json());
  const endpoint = agentData.endpoints.find(e => e.type === 'a2a');

  // 4. 与已验证智能体交互
  const result = await interactWithAgent(endpoint.url);

  // 5. 提交反馈
  await reputationRegistry.giveFeedback(
    targetAgentId,
    result.success ? 90 : 30,
    0,
    result.success ? 'starred' : 'failed',
    '',
    endpoint.url,
    '',
    ''
  );

  return result;
}

与 x402 支付集成

ERC-8004 和 x402 协同工作,实现可信的付费智能体交互:

import { IdentityRegistry, ReputationRegistry } from '@chaoschain/sdk';
import { wrapFetchWithPayment } from 'thirdweb/x402';

async function payTrustedAgent(agentId, serviceUrl) {
  // 1. 验证信任
  const summary = await reputationRegistry.getSummary(agentId);
  if (summary.averageScore < 80) {
    throw new Error('智能体信任度不足以进行支付');
  }

  // 2. 发送付费请求
  const fetchWithPayment = wrapFetchWithPayment({
    client,
    account,
    paymentOptions: { maxValue: "1000000" },
  });

  const response = await fetchWithPayment(serviceUrl);
  return response.json();
}

应用场景

DeFi 交易智能体

在委托资金前验证策略智能体:

const strategyAgents = await identityRegistry.searchByCapability('defi-trading');
const trustedAgents = [];

for (const agent of strategyAgents) {
  const summary = await reputationRegistry.getSummary(agent.id);
  if (summary.averageScore >= 85 && summary.totalFeedback >= 100) {
    trustedAgents.push(agent);
  }
}

多智能体工作流

为复杂任务协调可信智能体:

const workflow = {
  research: await findTrustedAgent('research', 80),
  analysis: await findTrustedAgent('analysis', 85),
  execution: await findTrustedAgent('execution', 90),
};

// 使用已验证信任的智能体执行
await executeWorkflow(workflow);

验证注册表

对于高风险操作,使用验证注册表进行额外验证:

模型 机制 最适合
基于声誉 客户端反馈 低风险、高频
加密经济 质押 + 罚没 中等风险金融
zkML 零知识证明 隐私保护
TEE 证明 硬件隔离 高保障

Celo 网络参考

网络 链 ID RPC 端点
Celo 主网 42220 https://forno.celo.org
Celo Sepolia 11142220 https://forno.celo-sepolia.celo-testnet.org

更多资源

相关技能

  • x402 – AI 智能体支付层
  • celo-rpc – Celo 区块链交互
  • viem – TypeScript 以太坊库