Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-5489, which embeds hyperlinks in NFTs so that users can click an NFT and navigate to a URL configured by its owner.

This article translates, summarizes, and supplements the material linked below.

Overview

The proposal introduces an extension to ERC-721 NFTs called the NFT hyperlink extension (hNFT). NFTs implementing it are referred to as hNFTs.

An hNFT owner can authorize a particular address, whether an externally owned account (EOA) or a contract address, to manage a URL slot and can revoke that authorization at any time. The authorized address can manage the URL associated with its slot.

A slot is a location for storing metadata, particularly a hyperlink.

Each slot uses an address as its key and a URI as its value. An example is {"0xabc123...": "metadata"}.

Authorizing a slot to an address means permitting that address to manage the corresponding slot.

Motivation

As NFTs attract attention, they may become an important medium for Web3.

The core NFT interfaces do not provide end users with a standardized mechanism for attaching rich text, videos, or images to an NFT. Many industries could benefit from this functionality.

Standardizing the attachment, editing, and display of customizable information would be useful. The proposal uses hyperlinks as a mechanism for attaching such information to NFTs and defines how those links are managed and displayed.

Specification

Interface

javascript
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;

interface IERC5489 {
    event SlotAuthorizationCreated(uint256 indexed tokenId, address indexed slotManagerAddr);

    event SlotAuthorizationRevoked(uint256 indexed tokenId, address indexed slotManagerAddr);

    event SlotUriUpdated(uint256 indexed tokenId, address indexed slotManagerAddr, string uri);

    function authorizeSlotTo(uint256 tokenId, address slotManagerAddr) external;

    function revokeAuthorization(uint256 tokenId, address slotManagerAddr) external;

    function revokeAllAuthorizations(uint256 tokenId) external;

    function setSlotUri(
        uint256 tokenId,
        string calldata newUri
    ) external;

    function getSlotUri(uint256 tokenId, address slotManagerAddr)
        external
        view
        returns (string memory);
}

Event

SlotAuthorizationCreated

Emitted when an address is authorized to change a URI slot associated with an NFT.

SlotAuthorizationRevoked

Emitted when that authorization is revoked, allowing associated permissions or incentives to be discontinued.

SlotUriUpdated

Emitted when an address updates a URI slot associated with an NFT.

Functions

authorizeSlotTo

Grants the address specified by slotManagerAddr permission to manage the hyperlink associated with the NFT identified by tokenId.

The function may be implemented as public or external.

revokeAuthorization

Revokes the hyperlink management authorization of slotManagerAddr for the NFT identified by tokenId.

The function may be implemented as public or external.

revokeAllAuthorizations

Revokes all slot management authorizations for the NFT identified by tokenId.

The function may be implemented as public or external.

setSlotUri

Sets a URI slot for the NFT identified by tokenId, associated with slotManagerAddr.

Only an address authorized through authorizeSlotTo may manage the applicable slot.

The function may be implemented as public or external.

getSlotUri

Returns the URI associated with the specified NFT and slot.

The URI must reference a JSON document conforming to the EIP-5489 Metadata JSON schema.

The function may be implemented as pure or view, as appropriate.

Authorization

The authorizeSlotTo, revokeAuthorization, and revokeAllAuthorizations functions may only be executed when the message sender is the token owner.

Metadata JSON schema

json
{
    "title": "AD Metadata",
    "type": "object",
    "properties": {
        "icon": {
            "type": "string",
            "description": "A URI pointing to a resource with mime type image/* representing the slot's occupier. Consider making any images at a width between 48 and 1080 pixels and aspect ration between 1.91:1 and 4:5 inclusive. Suggest to show this as an thumbnail of the target resource"
        },
        "description": {
            "type": "string",
            "description": "A paragraph which briefly introduce what is the target resource"
        },
        "target": {
            "type": "string",
            "description": "A URI pointing to target resource, sugguest to follow 30X status code to support more redirections, the mime type and content rely on user's setting"
        } 
    }
}

Additional Notes

URIs provide sufficient flexibility to accommodate a variety of use cases.

Authorizing Slots to Addresses

Using addresses as slot keys provides a flexible way to identify and manage independent slots.

Backward Compatibility

The proposal is designed to be fully compatible with EIP-721.

Reference Implementation

javascript
//SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;

import "./IERC5489.sol";

contract ERC5489 is IERC5489, ERC721Enumerable, Ownable {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(uint256 => EnumerableSet.AddressSet) tokenId2AuthroizedAddresses;
    mapping(uint256 => mapping(address=> string)) tokenId2Address2Value;
    mapping(uint256 => string) tokenId2ImageUri;

    string private _imageURI;
    string private _name;

    constructor() ERC721("Hyperlink NFT Collection", "HNFT") {}

    modifier onlyTokenOwner(uint256 tokenId) {
        require(_msgSender() == ownerOf(tokenId), "should be the token owner");
        _;
    }

    modifier onlySlotManager(uint256 tokenId) {
        require(_msgSender() == ownerOf(tokenId) || tokenId2AuthroizedAddresses[tokenId].contains(_msgSender()), "address should be authorized");
        _;
    }

    function setSlotUri(uint256 tokenId, string calldata value) override external onlySlotManager(tokenId) {
        tokenId2Address2Value[tokenId][_msgSender()] = value;

        emit SlotUriUpdated(tokenId, _msgSender(), value);
    }

    function getSlotUri(uint256 tokenId, address slotManagerAddr) override external view returns (string memory) {
        return tokenId2Address2Value[tokenId][slotManagerAddr];
    }

    function authorizeSlotTo(uint256 tokenId, address slotManagerAddr) override external onlyTokenOwner(tokenId) {
        require(!tokenId2AuthroizedAddresses[tokenId].contains(slotManagerAddr), "address already authorized");
        
        _authorizeSlotTo(tokenId, slotManagerAddr);
    }

    function _authorizeSlotTo(uint256 tokenId, address slotManagerAddr) private {
        tokenId2AuthroizedAddresses[tokenId].add(slotManagerAddr);
        emit SlotAuthorizationCreated(tokenId, slotManagerAddr);
    }

    function revokeAuthorization(uint256 tokenId, address slotManagerAddr) override external onlyTokenOwner(tokenId) {
        tokenId2AuthroizedAddresses[tokenId].remove(slotManagerAddr);
        delete tokenId2Address2Value[tokenId][slotManagerAddr];

        emit SlotAuthorizationRevoked(tokenId, slotManagerAddr);
    }

    function revokeAllAuthorizations(uint256 tokenId) override external onlyTokenOwner(tokenId) {
        for (uint256 i = tokenId2AuthroizedAddresses[tokenId].length() - 1;i > 0; i--) {
            address addr = tokenId2AuthroizedAddresses[tokenId].at(i);
            tokenId2AuthroizedAddresses[tokenId].remove(addr);
            delete tokenId2Address2Value[tokenId][addr];

            emit SlotAuthorizationRevoked(tokenId, addr);
        }

        if (tokenId2AuthroizedAddresses[tokenId].length() > 0) {
            address addr = tokenId2AuthroizedAddresses[tokenId].at(0);
            tokenId2AuthroizedAddresses[tokenId].remove(addr);
            delete tokenId2Address2Value[tokenId][addr];

            emit SlotAuthorizationRevoked(tokenId, addr);
        }
    }

    function isSlotManager(uint256 tokenId, address addr) public view returns (bool) {
        return tokenId2AuthroizedAddresses[tokenId].contains(addr);
    }

    // !!expensive, should call only when no gas is needed;
    function getSlotManagers(uint256 tokenId) external view returns (address[] memory) {
        return tokenId2AuthroizedAddresses[tokenId].values();
    }

    function _mintToken(uint256 tokenId, string calldata imageUri) private {
        _safeMint(msg.sender, tokenId);
        tokenId2ImageUri[tokenId] = imageUri;
    }

    function mint(string calldata imageUri) external {
        uint256 tokenId = totalSupply() + 1;
        _mintToken(tokenId, imageUri);
    }

    function mintAndAuthorizeTo(string calldata imageUri, address slotManagerAddr) external {
        uint256 tokenId = totalSupply() + 1;
        _mintToken(tokenId, imageUri);
        _authorizeSlotTo(tokenId, slotManagerAddr);
    }

    function tokenURI(uint256 _tokenId) public view override returns (string memory) {
        require(
            _exists(_tokenId),
            "URI query for nonexistent token"
        );

        return
            string(
                abi.encodePacked(
                    "data:application/json;base64,",
                    Base64.encode(
                        bytes(
                            abi.encodePacked(
                                '{"name":"',
                                abi.encodePacked(
                                    _name,
                                    " # ",
                                    Strings.toString(_tokenId)
                                ),
                                '",',
                                '"description":"Hyperlink NFT collection created with Parami Foundation"',
                                '}'
                            )
                        )
                    )
                )
            );
    }
}

Conclusion

ERC-5489 introduces a mechanism for embedding hyperlinks in NFTs and allowing users to navigate to URLs configured through the NFT's authorized slots.

I plan to add implementation details in a future update.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777