EIPs Explained

ERC-5489 · Final(最终) · ERC · 2022-08-16

ERC-5489: NFT Hyperlink Extension

一个 ERC-721 扩展,为每个 NFT 提供超链接槽位:所有者授权地址管理某个槽位,每个槽位指向一个 URI,所有者可以随时撤销。

它解决什么问题?

ERC-721 代币有一个由集合合约控制的 tokenURI。对于代币的所有者来说,没有标准方式可以附加额外内容(项目链接、广告、视频),也无法让别人这样做。

ERC-5489 把 NFT 变成类似小型广告牌的东西。所有者把**槽位(slot)**分配给其他地址。每个槽位持有者在 NFT 上发布一个 URI,应用可以展示这些链接。由于授权槽位是链上操作,因此 dApp 可以做到,例如,奖励授予它槽位的 NFT 所有者,并在槽位被撤销时停止奖励。

它如何运作

槽位是每个代币的映射中的一项,以管理者的地址为键。

函数 谁可以调用 效果
authorizeSlotTo(tokenId, slotManagerAddr) 代币所有者 为该地址创建一个槽位
revokeAuthorization(tokenId, slotManagerAddr) 代币所有者 移除一个槽位
revokeAllAuthorizations(tokenId) 代币所有者 移除所有槽位
setSlotUri(tokenId, newUri) 已授权的管理者 设置调用者自己槽位的 URI
getSlotUri(tokenId, slotManagerAddr) 任何人 读取某个槽位的 URI

必须 emit 事件 SlotAuthorizationCreated、SlotAuthorizationRevoked 和 SlotUriUpdated,以便索引器和前端跟踪槽位。supportsInterface 对 0x8f65987b 返回 true(ERC-165)。

每个槽位 URI 必须指向一个包含三个可选字段的 JSON 文档:

{
  "icon": "ipfs://<cid>/logo.png",
  "description": "Short text about the linked resource",
  "target": "https://example.com/landing"
}

icon 是缩略图,description 是简短介绍,target 是用户点击 NFT 链接时打开的 URI。

示例代码

所有者授予槽位,管理者设置其链接,查看者读取它(ethers v6):

import { Contract } from "ethers";

const abi = [
  "function authorizeSlotTo(uint256 tokenId, address slotManagerAddr)",
  "function setSlotUri(uint256 tokenId, string newUri)",
  "function getSlotUri(uint256 tokenId, address slotManagerAddr) view returns (string)",
  "function supportsInterface(bytes4) view returns (bool)",
];

const asOwner = new Contract(hnft, abi, ownerSigner);
if (!(await asOwner.supportsInterface("0x8f65987b"))) throw new Error("not ERC-5489");
await (await asOwner.authorizeSlotTo(1n, adManager)).wait();

const asManager = new Contract(hnft, abi, adManagerSigner);
await (await asManager.setSlotUri(1n, "ipfs://<cid>/slot.json")).wait();

const uri = await new Contract(hnft, abi, provider).getSlotUri(1n, adManager);
const meta = await (await fetch(toGatewayUrl(uri))).json();   // { icon, description, target }

需要注意

  • 状态为 Final。
  • 槽位内容由槽位管理者控制,而不是集合。前端应把 target 链接视为不可信,并防范钓鱼。
  • 规范没有说明槽位在代币转移后是否保留;请查看具体实现(参考代码在该 ERC 中有链接)。
  • 规范没有限定每个代币的槽位数量,因此 revokeAllAuthorizations 可能变得很昂贵。

#nft #erc-721 #hyperlink #metadata #advertising

详细信息

作者
IronMan_CH (@coderfengyun)
状态
Final(最终)
类型
Standards Track / ERC
创建日期
2022-08-16
依赖的提案

机器可读数据: Markdown · JSON