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-7644, which proposes a name registry for registering and managing unique names associated with NFTs for a specified period.

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

I have also covered other EIPs.

Overview

This standard proposes an interface that adds a naming mechanism to ERC-721 tokens. Each token can be assigned a unique name with an expiration date, with uniqueness enforced within the NFT contract.

NFTs are uniquely identified within a contract by their tokenId. This proposal adds a human-readable name as another means of identification.

The interface includes functions for assigning, updating, and querying names. A registered name remains associated with its token until the specified expiration time, subject to the implementation's update rules.

The address authorized to assign names may vary depending on the use case.

See the following article for ERC-721.

https://chaldene.net/erc721

Motivation

ENS already provides a mechanism for associating unique names with addresses, including EOAs.

This proposal applies a similar concept to NFTs, associating usernames with tokens to make them easier to identify.

Intuitive Identification

NFTs are normally identified by token IDs, which are not particularly intuitive. Adding usernames can make NFTs easier to manage and use.

Username Economy

A username registration mechanism can support identity-related applications and social interactions.

Combining Usernames and NFTs

Combining usernames with NFTs facilitates applications involving social interactions and personalized digital assets.

Mechanism

A conforming contract must implement the following interface.

js
pragma solidity ^0.8.0;

/**
 * @title INameRegistry
 * @dev Interface for the NameRegistry smart contract.
 * This interface allows interaction with a NameRegistry, 
 * enabling the registration, management, and lookup of names 
 * with associated expiry dates tied to specific tokens.
 */
interface IERC7644 /* is IERC721 */ {

    /**
     * @dev Emitted when the name of a token is changed.
     * @param tokenId The token ID whose name is changed.
     * @param oldName The previous name of the token.
     * @param newName The new name assigned to the token.
     * @param expiryDate The expiry date of the new name registration.
     */
    event NameChanged(uint256 indexed tokenId, bytes32 oldName, bytes32 newName, uint256 expiryDate);

    /**
     * @dev Returns the name of the specified token, if the name has not expired.
     * @param tokenId The token ID to query for its name.
     * @return The name of the token, or an empty bytes32 if no name is set or it has expired.
     */
    function nameOf(uint256 tokenId) external view returns (bytes32);

    /**
     * @dev Returns the token ID associated with a given name, if the name registration has not expired.
     * @param _name The name to query for its associated token ID.
     * @return The token ID associated with the name, or zero if no token is found or the name has expired.
     */
    function tokenIdOf(bytes32 _name) external view returns (uint256);

    /**
     * @dev Allows a token owner to set or update the name of their token, subject to a duration for the name's validity.
     * @param tokenId The token ID whose name is to be set or updated.
     * @param _name The new name to assign to the token.
     * @param duration The duration in seconds for which the name is valid, starting from the time of calling this function.
     * Note: The name must be unique and not currently in use by an active (non-expired) registration.
     */
    function setName(uint256 tokenId, bytes32 _name, uint256 duration) external;

    /**
     * @dev Returns the tokenId and expiryDate for a given name, if the name registration has not expired.
     * @param _name The name to query for its associated token ID and expiry date.
     * @return tokenId The token ID associated with the name.
     * @return expiryDate The expiry date of the name registration.
     */
    function nameInfo(bytes32 _name) external view returns (uint256 tokenId, uint256 expiryDate);
	
}

NameChanged

Emitted when the name associated with a particular token ID changes. The event records the previous name, the new name, and the expiration time of the new registration.

  • Parameters
    • tokenId
      • ID of the token whose name changed.
    • oldName
      • Previous name.
    • newName
      • New name.
    • expiryDate
      • Expiration time of the new name registration.

nameOf

Returns the name associated with a specified token ID.

  • Arguments
    • tokenId
      • Token ID whose name is requested.
  • Return value
    • The token's name as a bytes32.
    • An empty bytes32 if no valid name is registered or the registration has expired.

tokenIdOf

Returns the token ID associated with the specified name.

  • Arguments
    • _name
      • Name whose associated token ID is requested.
  • Return value
    • Associated token ID as a uint256.
    • Zero if the name cannot be found or has expired.

setName

Allows a token owner to assign or update the token's name, specifying its validity period in seconds.

The name must be unique and must not already be assigned through an active registration.

  • Arguments
    • tokenId
      • Token ID to which the name is assigned.
    • _name
      • New name.
    • duration
      • Validity period in seconds.

nameInfo

Returns the token ID and expiration time associated with a name. The original article describes zero values for missing or expired registrations.

  • Arguments
    • _name
      • Name whose information is requested.
  • Return values
    • Associated token ID as a uint256.
    • Expiration time as a uint256.

Additional Notes

Name Expiration

Expiration allows obsolete or unused usernames to become available again.

Without expiration, a name could remain associated with a token ID indefinitely unless its holder explicitly changes the registration.

An expiration mechanism allows the association to cease being valid after a specified period, making the name available to other users under the registration rules.

Name Uniqueness

Names associated with NFTs must be unique. Duplicate names could cause confusion or undermine applications relying on name resolution.

For example, if an application permits an NFT with a particular name to withdraw funds, assigning the same name to multiple NFTs could undermine that authorization rule.

Applications should also account for the possibility that an expired name is subsequently registered to a different token.

Name Registration System

A username registration mechanism can support fair access to names and reduce abuse.

Reservation and renewal mechanisms can help manage demand for names while limiting indefinite monopolization. Their effectiveness depends on the particular registration policy.

Compatibility

The extension is designed to remain compatible with ERC-721.

Reference Implementation

js
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract ERC7644 is ERC721 {
    event NameChanged(uint256 indexed tokenId, bytes32 oldName, bytes32 newName, uint256 expiryDate);

    struct NameRegistration {
        uint256 tokenId;
        uint256 expiryDate;
    }

    mapping(uint256 => bytes32) private _tokenNames;
    mapping(bytes32 => NameRegistration) private _nameRegistrations;
    mapping(uint256 => uint256) private _lastSetNameTime;

    uint256 public constant MAX_DURATION = 10 * 365 days;
    uint256 public constant MIN_SET_NAME_INTERVAL = 1 days;

    constructor() ERC721("Asd Token", "ASDT") {}

    function nameOf(uint256 tokenId) public view returns (bytes32) {
        if(_tokenNames[tokenId] != bytes32(0) && _nameRegistrations[_tokenNames[tokenId]].expiryDate > block.timestamp)
        {
            return _tokenNames[tokenId];
        }else{
            return bytes32(0);
        }
    }

    function tokenIdOf(bytes32 _name) public view returns (uint256) {
        require(_nameRegistrations[_name].expiryDate > block.timestamp, "NameRegistry: Name expired");
        if(_nameRegistrations[_name].tokenId > 0)
        {
            return _nameRegistrations[_name].tokenId;
        }else{
            return uint256(0);
        }
    }

    function setName(uint256 tokenId, bytes32 _name, uint256 duration) public {
        require(ownerOf(tokenId) == msg.sender, "NameRegistry: Caller is not the token owner");
        require(duration <= MAX_DURATION, "NameRegistry: Duration exceeds maximum limit");
        require(block.timestamp - _lastSetNameTime[tokenId] >= MIN_SET_NAME_INTERVAL, "NameRegistry: Minimum interval not met");
        require(tokenIdOf(_name) == uint256(0) || tokenIdOf(_name) == tokenId, "NameRegistry: Name already in use and not expired");

        bytes32 oldName = _tokenNames[tokenId];
        uint256 expiryDate = block.timestamp + duration;
        _setTokenName(tokenId, _name, expiryDate);

        emit NameChanged(tokenId, oldName, _name, expiryDate);

        _lastSetNameTime[tokenId] = block.timestamp;
    }

    function nameInfo(bytes32 _name) public view returns (uint256, uint256) {
        require(_nameRegistrations[_name].tokenId > 0 && _nameRegistrations[_name].expiryDate > block.timestamp, "NameRegistry: Name expired or does not exist");
        NameRegistration memory registration = _nameRegistrations[_name];
        return (registration.tokenId, registration.expiryDate);
    }

    function _setTokenName(uint256 tokenId, bytes32 _name, uint256 expiryDate) internal {
        _tokenNames[tokenId] = _name;
        _nameRegistrations[_name] = NameRegistration(tokenId, expiryDate);
    }
}

Security

Preventing Abuse and Limiting Resource Accumulation

Policies such as minimum registration intervals, maximum registration durations, and restrictions on consecutive registrations can help mitigate spam and abuse.

For example, an implementation may impose a waiting period between expiration of one registration and creation of another.

These policies can discourage indefinite monopolization and improve access to desirable names.

Username Restrictions

The article recommends restricting usernames to between 3 and 32 characters for indexing and gas efficiency.

Restricting the character set to [a-zA-Z0-9] can simplify representation and reduce certain forms of naming abuse. Implementations should also define how case differences and uniqueness are handled.

Citation

Chen Liaoyuan (@chenly), "ERC-7644: ERC-721 Name Registry Extension [DRAFT]," Ethereum Improvement Proposals, no. 7644, March 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7644.

Conclusion

ERC-7644 proposes a name registry for ERC-721 NFTs, enabling the registration and management of unique names with expiration times.

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

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/