EIPs Explained

ERC-5489 · Final · ERC · 2022-08-16

ERC-5489: NFT Hyperlink Extension

An ERC-721 extension that gives each NFT hyperlink slots: the owner authorizes addresses to manage a slot, each slot points to a URI, and the owner can revoke at any time.

What problem does it solve?

An ERC-721 token has one tokenURI, controlled by the collection contract. There is no standard way for the token's owner to attach extra content (a link to a project, an ad, a video) or to let someone else do so.

ERC-5489 turns an NFT into something like a small billboard. The owner hands out slots to other addresses. Each slot holder publishes a URI on the NFT, and apps can display those links. Since authorizing a slot is an on-chain action, a dApp can, for example, reward NFT owners for granting it a slot and stop rewards when the slot is revoked.

How it works

A slot is an entry in a per-token map keyed by the manager's address.

Function Who may call Effect
authorizeSlotTo(tokenId, slotManagerAddr) token owner Creates a slot for that address
revokeAuthorization(tokenId, slotManagerAddr) token owner Removes one slot
revokeAllAuthorizations(tokenId) token owner Removes every slot
setSlotUri(tokenId, newUri) an authorized manager Sets the URI of the caller's own slot
getSlotUri(tokenId, slotManagerAddr) anyone Reads a slot's URI

Events SlotAuthorizationCreated, SlotAuthorizationRevoked and SlotUriUpdated must be emitted, so indexers and front ends can track slots. supportsInterface returns true for 0x8f65987b (ERC-165).

Each slot URI must point to a JSON document with three optional fields:

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

icon is a thumbnail image, description a short blurb, and target the URI to open when a user clicks the NFT's link.

Sample code

Owner grants a slot, the manager sets its link, a viewer reads it (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 }

Things to know

  • Status is Final.
  • Slot content is controlled by the slot manager, not the collection. Front ends should treat target links as untrusted and guard against phishing.
  • The spec does not say whether slots survive a token transfer; check the implementation (the reference code is linked from the ERC).
  • The spec defines no limit on the number of slots per token, so revokeAllAuthorizations can become expensive.

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

Details

Authors
IronMan_CH (@coderfengyun)
Status
Final
Type
Standards Track / ERC
Created
2022-08-16
Requires

Machine-readable: Markdown · JSON