---
eip: 6381
label: ERC-6381
title: Public Non-Fungible Token Emote Repository
status: Final
type: Standards Track
category: ERC
created: 2023-01-22
requires: 165
official: https://eips.ethereum.org/EIPS/eip-6381
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6381.md
canonical: https://eips.huatuo.xyz/zh/eip-6381/
lang: zh
tldr: 一个单一的公共仓库合约，任何人都可以用 emoji 对任意 NFT 做出反应，无需改动 NFT 合约，就能为每个系列（无论新旧）提供标准的链上反应。
tags: [nft, social, emoji, reactions, repository]
---

# ERC-6381: Public Non-Fungible Token Emote Repository

> React to any Non-Fungible Tokens using Unicode emojis.

**TL;DR:** 一个单一的公共仓库合约，任何人都可以用 emoji 对任意 NFT 做出反应，无需改动 NFT 合约，就能为每个系列（无论新旧）提供标准的链上反应。

## 它解决什么问题？

NFT 市场和应用会显示点赞和反应，但这些数据存放在各平台自己的数据库里。它们无法验证，无法被其他应用读取，也无法驱动链上逻辑，例如当足够多的人对某个 NFT 做出反应后它就会进化。

ERC-6381 定义了一个**公共表情仓库**：一个共享合约，打算在每条链上部署到同一地址，记录哪个地址用哪个 emoji 对哪个代币做出了反应。由于它是独立的仓库而不是代币的扩展，所以对任何现有的 [ERC-721](/eip-721/) 或 [ERC-1155](/eip-1155/) 系列都有效，无需对该系列做任何改动。

## 它如何运作

- emoji 由一个 `bytes4` 的 Unicode 值标识。Unicode 之外的值可以作为自定义表情使用，但应用需要知道如何渲染它们。
- `emote(collection, tokenId, emoji, state)` 添加（`true`）或移除（`false`）你的反应。每个地址对每个代币的每个 emoji 最多只能有一个有效反应，因此刷屏不会虚增计数。
- `emoteCountOf(collection, tokenId, emoji)` 返回计数；`hasEmoterUsedEmote(...)` 检查特定地址。
- 批量版本（`bulkEmote`、`bulkEmoteCountOf`、`haveEmotersUsedEmotes`）可以节省 gas 和 RPC 调用。
- **预签名表情**：用户签署一条消息，任何人都可以用 `presignedEmote(...)` 或 `bulkPresignedEmote(...)` 提交它，例如用于代付 gas，或记录在链下获得的反应。消息为 `keccak256(abi.encode(DOMAIN_SEPARATOR, collection, tokenId, emoji, state, deadline))`，域分隔符包含链 ID 和仓库地址。
- 只有当状态真正发生变化时，才会触发 `Emoted(emoter, collection, tokenId, emoji, on)` 事件。
- 该仓库的 ERC-165 接口 ID 是 `0xd9fac55a`。规范给出的预期地址是 `0x31107354b61A0412E722455A771bC462901668eA`（前缀 `0x311073` 拼出了 "EMOTE"）。

## 示例代码

对 NFT 做出反应并读取计数（ethers v6）：

```ts
import { Contract, toUtf8Bytes, hexlify } from "ethers";

const REPO = "0x31107354b61A0412E722455A771bC462901668eA"; // per the spec; verify it is deployed on your chain
const repo = new Contract(REPO, [
  "function emote(address collection, uint256 tokenId, bytes4 emoji, bool state)",
  "function emoteCountOf(address collection, uint256 tokenId, bytes4 emoji) view returns (uint256)",
], signer);

// U+1F525 (fire) as the first 4 bytes of its UTF-8 encoding: 0xf09f94a5
const FIRE = hexlify(toUtf8Bytes("🔥"));

await (await repo.emote(collection, 1234n, FIRE, true)).wait();
console.log(await repo.emoteCountOf(collection, 1234n, FIRE)); // 1n
```

## 需要注意

- 状态：**Final**。
- 规范说的是"Unicode 标识符"，但没有为 `bytes4` 固定某一种编码。示例使用 UTF-8 字节（适用于大多数单码位 emoji）；希望共享计数的应用必须就同一种编码达成一致。
- 仓库不会检查代币是否存在，因此可以对从未被铸造的代币做出反应。索引器应据此进行过滤。
- 预签名消息在截止时间之前可以被重复使用。如果你的应用会撤销反应，请使用较短的截止时间，否则有人可能重放该签名来重新添加。
- 仓库不持有任何资产，所以主要风险在于签名处理，以及把原始计数当作可信信号：它们可以被大量地址刷出来。


---

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