---
eip: 7861
label: ERC-7861
title: ERC-721 Verifiable Credential Extension
status: Draft
type: Standards Track
category: ERC
created: 2025-01-14
requires: 165, 721
official: https://eips.ethereum.org/EIPS/eip-7861
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7861.md
canonical: https://eips.huatuo.xyz/zh/eip-7861/
lang: zh
tldr: 一个 ERC-721 扩展，把 NFT 合集变成一组可验证凭证，在一个标准接口中公开发行者、凭证类型、加密和验证方法、每个代币的凭证 URI 以及撤销状态。
tags: [nft, erc721, credentials, identity, verifiable-credentials]
---

# ERC-7861: ERC-721 Verifiable Credential Extension

> An extension to ERC-721 that adds collection-wide verifiable credential properties, this allows native support for onchain credentials.

**TL;DR:** 一个 ERC-721 扩展，把 NFT 合集变成一组可验证凭证，在一个标准接口中公开发行者、凭证类型、加密和验证方法、每个代币的凭证 URI 以及撤销状态。

## 它解决什么问题？

各项目已经在用 NFT 表示文凭、会员资格、KYC 证明等类似声明，但每个合集都自创了一套方式来说明是谁发行的、实际凭证存放在哪里、是否加密、是否已被撤销。验证方必须为每个合集编写定制代码。

ERC-7861 在 [ERC-721](/eip-721/) 之上增加了一个小型共享接口，使任何平台都能以相同方式发现和检查凭证 NFT。它在设计时考虑了 W3C 可验证凭证（Verifiable Credentials），但也可以通过 NFT 把任何私有的链下负载关联到钱包。

## 它如何运作

合集范围的属性（对每个代币都相同）：

- `issuer()`：发行者的 DID 或地址（空字符串表示没有发行者）。
- `credentialType()`：该合集所持有的凭证类型。
- `encryptionMethod()`：**当且仅当**凭证未加密时返回空字符串；否则返回所用方法的名称。额外的解密细节可以在别处公开。
- `verificationMethod()`：如何验证凭证的证明，最好与 W3C 的"verification method"概念一致。

每个代币：

- `credentialURI(tokenId)`：凭证的存放位置（IPFS、带访问控制的私有服务器等）；如果获取方式不同，则为空字符串。
- `isRevoked(tokenId)`：撤销后为 `true`；对于不存在的代币也可能为 `true`。撤销可以是销毁 NFT、合约中的列表，或链下的列表。

可选事件 `CredentialIssued(tokenId, to)` 和 `CredentialRevoked(tokenId)` 让索引器能够跟踪其生命周期。

验证方的流程：在持有者的钱包中找到凭证 NFT → 从 `credentialURI` 获取 → 如果设置了 `encryptionMethod()` 则解密（可能需要持有者同意）→ 用 `verificationMethod()` 验证 → 检查 `isRevoked`。

## 示例代码

用 ethers v6 检查凭证：

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

const vc = new Contract(collection, [
  "function issuer() view returns (string)",
  "function credentialType() view returns (string)",
  "function encryptionMethod() view returns (string)",
  "function verificationMethod() view returns (string)",
  "function credentialURI(uint256) view returns (string)",
  "function isRevoked(uint256) view returns (bool)",
], provider);

if (await vc.isRevoked(tokenId)) throw new Error("credential revoked");

const [iss, type, enc, method, uri] = await Promise.all([
  vc.issuer(), vc.credentialType(), vc.encryptionMethod(),
  vc.verificationMethod(), vc.credentialURI(tokenId),
]);
console.log({ iss, type, encrypted: enc !== "", method, uri });
// next: fetch `uri`, decrypt if needed, verify the proof per `method`
```

## 需要注意

- 状态为 **Draft**，Rationale 一节仍是 TODO。
- 当前文本中 ERC-165 接口 ID 并不清楚：规范给出的是 `0x7861069`（只有七位十六进制数字），而参考实现使用的是 `0x74699c4e`。在依赖 `supportsInterface` 之前，请先查看最终规范。
- 规范建议凭证应为**不可转让**；该行为请参阅 [ERC-5192](/eip-5192/)（最小化灵魂绑定）或 [ERC-4973](/eip-4973/)。
- 链上的一切，包括 `credentialURI`，都是公开的。请把敏感数据加密后放在链下。
- 对发行、撤销和设置合集属性实施严格的访问控制至关重要；参考实现省略了这一点。


---

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