---
eip: 7053
label: ERC-7053
title: Interoperable Digital Media Indexing
status: Final
type: Standards Track
category: ERC
created: 2023-05-22
official: https://eips.ethereum.org/EIPS/eip-7053
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7053.md
canonical: https://eips.huatuo.xyz/zh/eip-7053/
lang: zh
tldr: 一个简单的数字媒体链上索引：任何人都可以用文件的内容标识符（CID）和一些数据调用 commit()，触发的 Commit 事件就构成了该文件跨合约、可检索的历史记录。
tags: [media, provenance, cid, indexing, events]
---

# ERC-7053: Interoperable Digital Media Indexing

> A universal indexing method to record, discover and retrieve the history of digital media on EVM-compatible blockchains.

**TL;DR:** 一个简单的数字媒体链上索引：任何人都可以用文件的内容标识符（CID）和一些数据调用 commit()，触发的 Commit 事件就构成了该文件跨合约、可检索的历史记录。

## 它解决什么问题？

照片、视频和其他数字媒体会被复制、编辑、铸造成 NFT，并被许多系统引用。每个系统往往各自追踪文件，因此没有一个通用的键来回答"*这个确切的文件*被谁、在哪条链上记录过什么？"。来源（provenance）和元数据因此变得零散。

ERC-7053 提出了一个通用的键，即文件的**内容标识符（Content Identifier，CID）**，以及针对它记录日志的标准方式。由于 CID 是内容的密码学哈希，任何拥有该文件的人都可以重新计算它，并查询跨合约、跨 EVM 链针对它提交的所有记录。

## 它如何运作

1. 为媒体文件**计算 CID**。规范要求使用基于密码学哈希的内容地址，并说明它应与去中心化存储上使用的标识符相同，这样 CID 同时也能定位文件及其元数据。
2. 在符合规范的合约上**调用 `commit`**，传入 CID 和一个自由格式的 `commitData` 字符串（例如指向元数据的指针、操作描述或编辑记录）。
3. 合约**触发 `Commit` 事件**并返回区块号。参考实现还会按 CID 保存区块号，以便通过 `getCommits` 读回。

```solidity
event Commit(address indexed recorder, string indexed assetCid, string commitData);

function commit(string memory assetCid, string memory commitData)
    public returns (uint256 blockNumber);
```

一个文件的历史就是其 CID 对应的 `Commit` 事件的有序列表，可能跨越许多合约和链。在合约出现之前铸造的 NFT 也可以被索引，只需计算其 `tokenURI` 所指文件的 CID。

## 示例代码

提交记录并随后查询文件的历史（ethers v6）：

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

const abi = [
  "event Commit(address indexed recorder, string indexed assetCid, string commitData)",
  "function commit(string assetCid, string commitData) returns (uint256)",
];
const registry = new Contract(registryAddress, abi, signer);

const cid = "bafy...";                       // CID of the media file
await (await registry.commit(cid, JSON.stringify({ action: "captured" }))).wait();

// Indexed strings are stored as keccak256 hashes in the log topic,
// so filter by the hash of the CID.
const logs = await registry.queryFilter(registry.filters.Commit(null, id(cid)));
for (const l of logs) console.log(l.blockNumber, l.args.recorder, l.args.commitData);
```

## 需要注意

- **状态：Final。**
- 合约**不会**验证任何内容：它不检查 CID 是否有效，也不检查 `commitData` 是否属实。任何人都可以针对任何 CID 提交任何内容，因此信任来自 `recorder` 是*谁*，而不是记录本身存在。
- 由于 `assetCid` 是 indexed 的 `string`，日志 topic 中保存的是它的哈希而非文本。你可以按已知的 CID 过滤，但无法仅凭 topic 读回 CID；如果需要，请把它放在 `commitData` 或存储中。
- 索引器在根据日志构建历史时，应处理重组（reorg）以及可能漏掉的事件。


---

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