---
eip: 6785
label: ERC-6785
title: ERC-721 Utilities Information Extension
status: Draft
type: Standards Track
category: ERC
created: 2023-03-27
requires: 165, 721
official: https://eips.ethereum.org/EIPS/eip-6785
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6785.md
canonical: https://eips.huatuo.xyz/zh/eip-6785/
lang: zh
tldr: 一个 ERC-721 扩展草案：通过带完整变更历史的链上 URI 公布 NFT 赋予的权益（utility），并提供描述权益的元数据模式。
tags: [nft, utility, metadata, transparency]
---

# ERC-6785: ERC-721 Utilities Information Extension

> Provide easy access to information about the `utility` of an NFT via functions and the NFT's metadata

**TL;DR:** 一个 ERC-721 扩展草案：通过带完整变更历史的链上 URI 公布 NFT 赋予的权益（utility），并提供描述权益的元数据模式。

## 它解决什么问题？

许多 NFT 都承诺某种"权益"：活动入场、与创作者通话、折扣等。这些承诺通常只存在于网站或 Discord 帖子里，可能被悄悄修改，也是钓鱼攻击常用的诱饵（"在这里领取你的权益"）。买家没有可靠的链上记录来了解当初承诺了什么、条款又是如何变化的。

ERC-6785 为每个代币在链上放置一个指向权益说明的指针，保留每次变更的历史，并用结构化的 `utilities` 部分扩展 ERC-721 元数据 JSON。

## 它如何运作

合约接口（[ERC-165](/eip-165/) ID 为 `0xed231d73`）：

| 成员 | 用途 |
| --- | --- |
| `setUtilityUri(tokenId, uri)` | 设置或更改权益 URI。应仅限提供权益的一方调用。空字符串表示没有权益。 |
| `utilityUriOf(tokenId)` | 当前的权益 URI |
| `utilityHistoryOf(tokenId)` | 该代币拥有过的所有权益 URI，按顺序排列 |
| `UpdateUtility(tokenId, uri)` | 每次变更都必须触发，包括批量更新 |

URI 被有意设计为可变：访问说明可能依赖某个链下工具，而该工具之后可能迁移。历史记录让这些变更可以被审计。URI 可以指向受限内容，例如只有持有者用钱包登录后才会显示，并且可以包含当前状态，例如剩余的次数。

代币的常规元数据应遵循带有 `utilities` 对象的扩展 [ERC-721](/eip-721/) JSON 模式：

| 字段 | 是否必填 | 含义 |
| --- | --- | --- |
| `type` | 是 | 权益的类型 |
| `description` | 是 | 简短描述 |
| `t&c` | 是 | 条款与条件 |
| `properties` | 否 | 键值详情数组 |
| `expiry` | 否 | 铸造后权益保持有效的秒数 |

## 示例代码

一个授予两次 30 分钟视频通话、有效期约六个月的 NFT 的元数据：

```json
{
  "name": "Creator Pass #12",
  "description": "Holder pass",
  "image": "ipfs://<cid>/12.png",
  "utilities": {
    "type": "Video call",
    "description": "Private video call with the creator",
    "properties": [{ "sessions": 2 }, { "duration": 30 }, { "time_unit": "minutes" }],
    "expiry": 15770000,
    "t&c": "https://example.com/terms"
  }
}
```

读取当前权益及其历史（ethers v6）：

```ts
import { Contract } from "ethers";

const nft = new Contract(addr, [
  "function utilityUriOf(uint256) view returns (string)",
  "function utilityHistoryOf(uint256) view returns (string[])",
], provider);

const current = await nft.utilityUriOf(12n);
const history: string[] = await nft.utilityHistoryOf(12n);
console.log(current, `changed ${history.length} time(s)`);
```

## 需要注意

- 状态为 **Draft**：名称和模式可能会变化。
- 该标准只记录承诺，不强制执行。兑现权益仍是创作者的责任。
- 能调用 `setUtilityUri` 的人决定了持有者能看到什么，因此要严格限制。
- 在链上存储不断增长的 `string[]` 历史，每次更新都要消耗 gas。
- 原理（rationale）部分提到了 `getUtilityUri` 方法，但接口中定义的是 `utilityUriOf`，请使用后者。
- 若需要链上的使用权而非描述，请参阅 [ERC-4907](/eip-4907/)（租赁用户角色）和 [ERC-4400](/eip-4400/)（消费者角色）。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-6785
