> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monad.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# 如何在 Monad 上注册和使用 ERC-8004(Trustless Agents)构建

export const CopyToClipboard = ({value, children}) => {
  const [copied, setCopied] = useState(false);
  const handleCopy = async () => {
    try {
      await navigator.clipboard.writeText(value);
      setCopied(true);
      setTimeout(() => setCopied(false), 1000);
    } catch {
      const textarea = document.createElement("textarea");
      textarea.value = value;
      textarea.style.position = "fixed";
      textarea.style.opacity = "0";
      document.body.appendChild(textarea);
      textarea.select();
      document.execCommand("copy");
      document.body.removeChild(textarea);
      setCopied(true);
      setTimeout(() => setCopied(false), 1000);
    }
  };
  return <span style={{
    display: "inline",
    whiteSpace: "nowrap"
  }}>
      {children}
      <button onClick={handleCopy} title={copied ? "Copied!" : "Copy to clipboard"} style={{
    background: "none",
    border: "none",
    cursor: "pointer",
    padding: "2px",
    display: "inline-flex",
    alignItems: "center",
    verticalAlign: "middle",
    marginLeft: "4px",
    opacity: copied ? 1 : 0.4,
    transition: "opacity 0.15s"
  }} onMouseEnter={e => {
    if (!copied) e.currentTarget.style.opacity = "0.8";
  }} onMouseLeave={e => {
    if (!copied) e.currentTarget.style.opacity = "0.4";
  }}>
        {copied ? <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#22c55e" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
            <polyline points="20 6 9 17 4 12" />
          </svg> : <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
            <rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
            <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
          </svg>}
      </button>
    </span>;
};

本指南展示了如何在 Monad 上使用 ERC-8004 注册 AI 代理并构建无需信任的代理交互。

## 什么是 ERC-8004?

[ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) 是面向 Trustless Agents 的以太坊标准,提供三个用于代理身份、声誉和验证的链上注册表。它为 AI 代理和代理化服务(MCP、API 等)提供可携带的身份、可验证的历史记录和加密验证,使它们能够作为负责任的经济参与者运作。

该标准支持:

* **身份注册表**:代理通过一个 ERC-721 NFT 和代理卡片进行注册
* **声誉注册表**:用于代理交互的不可变反馈系统
* **验证注册表**:对代理工作的第三方验证

### 主要优势

* **可移植身份**:代理通过 ERC-721 代币在各平台间拥有持久、可转移的身份。
* **可验证声誉**:不可变的链上反馈为代理创建可审计的历史记录。
* **无需中介的信任**:加密验证使代理之间的无需信任交互得以实现,无需任何中心化实体。
* **经济互操作性**:代理可以使用 x402 自主发现、验证并相互支付。

## 核心组件

### 1. 身份注册表

每个代理铸造一个 ERC-721 代币。代币 ID 是该代理的唯一标识符,代币 URI 指向一张"代理卡片",其中包含:

* 名称和描述
* API 端点(A2A 协议、MCP、HTTP 等)
* 支持的信任模型
* DID/ENS 标识符
* 用于收款的代理钱包地址(如有)

### 2. 声誉注册表

在与代理交互后,客户端将结构化反馈提交上链:

* 度量属性的数值(例如,正常运行时间、成功率、质量)
* 用于分类的标签(例如,"fast"、"accurate"、"DeFi")
* 可选的 `feedbackURI`,用于详细的链下评价
* 用于数据完整性的内容哈希

反馈是**永久不可变的**——由此创建可审计的历史记录。

### 3. 验证注册表(即将推出)

对于高风险任务,第三方验证者可以在链上验证代理的工作。该注册表对验证模型(TEE、zkML、欺诈证明等)不持特定立场。

## 交互流程

```mermaid theme={null}
sequenceDiagram
    box Agent A
        participant Service as Service
    end
    box ERC-8004
        participant Registries as Registries
    end
    box Agent B
        participant Client as Client
    end

    Service->>Registries: 1. Register identity
    Client->>Registries: 2. Discover agents
    Client->>Registries: 3. Check reputation
    Client->>Service: 4. Service request + x402 payment
    Service->>Client: 5. Service response
    Client->>Registries: 6. Submit feedback
```

## 使用场景

### 代理服务市场

* **预言机**:代理提供可通过声誉发现的实时数据源(如价格馈送、天气、体育比分)。
* **市场评级与分析**:专业代理提供风险评估、信用评分和情感分析等服务。
* **作为代理的 API**:任何 API——例如天气、翻译或图像处理——都可以注册为代理,从而可被发现并可付费使用。
* **基于声誉的门控访问**:服务可以根据客户端的链上声誉历史对其进行筛选或限制。

### 代理路由系统

代理不必原生实现服务,而是可以调用路由系统,依据以下依据动态选择最佳服务提供者:

* **延迟**:为时间敏感任务路由到最快的可用代理
* **价格**:为大批量操作寻找最具性价比的提供者
* **声誉**:为关键操作选择评分较高的代理
* **专业化**:将任务需求匹配到代理能力

### AI 代理市场

* 代理注册带有定价的服务
* 客户端通过声誉发现代理
* 自动化的服务发现和付款

### 自主服务网络

* 代理雇佣其他代理执行子任务
* 基于声誉的信任决策
* 自动反馈闭环

### DeFi 代理协议

* 投资组合管理代理
* 交易策略代理
* 收益优化代理

### 企业代理生态系统

* 内部代理目录
* 跨组织代理协作
* 合规与审计记录

## 最佳实践

### 注册

* 使用描述性的代理名称和完善的文档。
* 提供多种端点类型以提高灵活性。
* 随着能力变化及时更新代理卡片。
* 使用 ENS 名称以便于发现。

### 声誉管理

* 每次交互后提交诚实反馈
* 使用一致的标签分类法
* 对重要交互附上详细评价
* 回应对您代理的反馈

### 安全

* 在付款前验证代理签名
* 在高价值交易前检查声誉
* 对关键操作使用验证注册表
* 监控对您代理的反馈

您可以在[此处](https://github.com/erc-8004/best-practices)找到更多信息。

## 高级功能

### 跨链代理发现

```ts theme={null}
// Bridge agent identity across chains
import { CCIPRouter } from "@chainlink/ccip";

async function bridgeAgentToMonad(agentId: string, sourceChain: string) {
  // Query agent card from source chain
  // Register mirror on Monad
  // Link reputation data
}
```

### 声誉聚合

```ts theme={null}
// Build custom reputation scoring
function calculateTrustScore(feedback: Feedback[]): number {
  const recentWeight = 0.7;
  const historicalWeight = 0.3;
  
  const recent = feedback.slice(0, 10);
  const historical = feedback.slice(10);
  
  const recentScore = average(recent.map(f => f.value));

  const historicalScore = average(historical.map(f => f.value));
  
  return recentScore * recentWeight + historicalScore * historicalWeight;
}
```

### 验证集成

```ts theme={null}
// TEE-based validation (coming soon)
async function validateWithTEE(
  agentId: string,
  task: any,
  proof: any
) {
  // Submit to validation registry
  // TEE verifies execution
  // On-chain proof recorded
}
```

## 资源

* [ERC-8004 规范](https://www.8004.org/learn)
* [ERC-8004 GitHub](https://github.com/erc-8004)
* [agent0 SDK](https://sdk.ag0.xyz/) - TypeScript 和 Python SDK,附带指南
* [8004scan.io](https://8004scan.io) - 浏览代理和声誉
* [Agentscan.info](http://Agentscan.info) - 浏览代理和声誉
* [8004agents.ai](http://8004agents.ai) - 浏览代理和声誉
* [Monad 开发者 Discord](https://discord.gg/monaddev)

## 合约地址

<ul>
  <li>
    <strong>身份注册表</strong>:

    <CopyToClipboard value="0x8004A169FB4a3325136EB29fA0ceB6D2e539a432">
      [`0x8004A169FB4a3325136EB29fA0ceB6D2e539a432`](https://monadvision.com/address/0x8004A169FB4a3325136EB29fA0ceB6D2e539a432)
    </CopyToClipboard>
  </li>

  <li>
    <strong>声誉注册表</strong>:

    <CopyToClipboard value="0x8004BAa17C55a88189AE136b182e5fdA19dE9b63">
      [`0x8004BAa17C55a88189AE136b182e5fdA19dE9b63`](https://monadvision.com/address/0x8004BAa17C55a88189AE136b182e5fdA19dE9b63)
    </CopyToClipboard>
  </li>

  <li>
    <strong>验证注册表</strong>:(即将推出)
  </li>
</ul>

## 需要帮助?

加入 [Monad 开发者 Discord](https://discord.gg/monaddev) 或联系 [team@8004.org](mailto:team@8004.org)

祝您构建愉快!🤖
