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 ERC7656, a proposal that extends ERC6551 with a registry for general-purpose contracts linked to specific NFTs. It covers the proposal as discussed in the original article published on June 16, 2024.

This article translates, summarizes, and expands on the specification linked below.

I also cover a variety of other EIPs.

Overview

The standard proposes a variation of ERC6551. It describes a mechanism that allows contracts created under ERC6551 to serve purposes other than accounts.

ERC6551 defines contract accounts linked to individual NFTs. Each NFT has a value called tokneId (a typo for token ID in the original article). For each tokenId, a contract called a token-bound account (TBA) can be created. The NFT holder controls the TBA. Because a TBA is a contract, it can receive other NFTs, fungible tokens (FTs), and ETH. This allows an NFT to hold other NFTs, FTs, and ETH through its associated account.

Token-bound account holding assets Source: https://zenn.dev/thirdweb_jp/articles/ce2c7bdc39ff85

When an NFT is bought or sold, control of its associated TBA automatically passes to the new NFT holder because the holder controls the account. An intuitive use case is an airdrop. To distribute tokens to NFT holders at a particular time, sending them to the associated TBAs can achieve the same effect as distributing them to the holders at that time.

OpenSea supported the display of ERC6551 assets when this article was written. Its interface provides a useful example.

OpenSea NFT detail page with a token-bound account https://opensea.io/assets/ethereum/0x582048c4077a34e7c3799962f1f8c5342a3f4b12/4

As shown above, an ERC6551 NFT has a bag button in the upper-left corner.

Assets displayed for the NFT's token-bound account

Selecting the bag button displays the assets held by the NFT's associated TBA. The original figures and screenshots are retained; their labels may remain in Japanese. For more details, see the following article.

[ERC6551] Understanding Token-Bound Accounts for NFTs

Motivation

ERC6551 provides a registry (ERC6551Registry) for deploying accounts owned by the NFT identified by a tokenId. However, ERC6551 requires contracts created through this registry to implement IERC6551Account and IERC6551Execute. This restricts the deployed contracts to accounts and limits flexibility. The proposed standard introduces a general-purpose registry for deploying different kinds of contracts associated with NFTs. Function and event names are also generalized so that they are not restricted to a specific use case. While ERC6551Registry deploys a contract linked to an NFT, the generalized approach allows registries to be adapted to the needs of individual projects.

The proposed ERC7656Registry is designed to avoid the restrictions of ERC6551. The new standard offers the following benefits.

  • Flexibility
    • NFTs can interact with different types of contracts.
    • New use cases and functionality become possible, including lending, fractional ownership of assets, and identity.
  • Compatibility
    • Compatibility with ERC6551 is maintained by allowing account-like contracts to be identified.
  • Innovation
    • Removing restrictions on the types of contracts associated with NFTs encourages experimentation in NFT applications.

Specification

The IERC7656Registry interface is defined as follows.

js
// interfaceId 0xc6bdc908
interface IERC7656Registry {
  /**
   * @notice The registry MUST emit the Created event upon successful contract creation.
   * @param contractAddress The address of the created contract
   * @param implementation The address of the implementation contract
   * @param salt The salt to use for the create2 operation
   * @param chainId The chain id of the chain where the contract is being created
   * @param tokenContract The address of the token contract
   * @param tokenId The id of the token
   */
  event Created(
    address contractAddress,
    address indexed implementation,
    bytes32 salt,
    uint256 chainId,
    address indexed tokenContract,
    uint256 indexed tokenId
  );

  /**
   * The registry MUST revert with CreationFailed error if the create2 operation fails.
   */
  error CreationFailed();

  /**
   * @notice Creates a token linked account for a non-fungible token.
   * If account has already been created, returns the account address without calling create2.
   * @param implementation The address of the implementation contract
   * @param salt The salt to use for the create2 operation
   * @param chainId The chain id of the chain where the account is being created
   * @param tokenContract The address of the token contract
   * @param tokenId The id of the token
   * Emits Created event.
   * @return account The address of the token linked account
   */
  function create(
    address implementation,
    bytes32 salt,
    uint256 chainId,
    address tokenContract,
    uint256 tokenId
  ) external returns (address account);

  /**
   * @notice Returns the computed token linked account address for a non-fungible token.
   * @param implementation The address of the implementation contract
   * @param salt The salt to use for the create2 operation
   * @param chainId The chain id of the chain where the account is being created
   * @param tokenContract The address of the token contract
   * @param tokenId The id of the token
   * @return account The address of the token linked account
   */
  function compute(
    address implementation,
    bytes32 salt,
    uint256 chainId,
    address tokenContract,
    uint256 tokenId
  ) external view returns (address account);
}

Created event

js
event Created(
address contractAddress,
address indexed implementation,
bytes32 salt,
uint256 chainId,
address indexed tokenContract,
uint256 indexed tokenId
);

This event is emitted when a contract is successfully created.

  • contractAddress
    • Address of the newly created contract.
  • implementation
    • Address of the implementation contract.
  • salt
    • Salt used for the create2 operation.
  • chainId
    • ID of the chain on which the contract is created.
  • tokenContract
    • Address of the token contract.
  • tokenId
    • ID of the token.

CreationFailed error

js
error CreationFailed();

This error is raised if the create2 operation fails.

create function

js
function create(
    address implementation,
    bytes32 salt,
    uint256 chainId,
    address tokenContract,
    uint256 tokenId
) external returns (address account);

Creates an account linked to an NFT. If the account already exists, the function returns its address without invoking create2. The Created event is emitted when account creation succeeds. Previously, the implementation parameter had to identify a contract conforming to IERC6551Account. This standard proposes allowing arbitrary contracts to be passed as the implementation parameter.

  • implementation
    • Address of the implementation contract.
  • salt
    • Salt used for the create2 operation.
  • chainId
    • ID of the chain on which the contract is created.
  • tokenContract
    • Address of the token contract.
  • tokenId
    • ID of the token.
  • account
    • Returns the address of the created contract.

compute function

Computes and returns the address of an account linked to an NFT. It is used to calculate the address without actually performing a create2 operation.

js
function compute(
address implementation,
bytes32 salt,
uint256 chainId,
address tokenContract,
uint256 tokenId
) external view returns (address account);
  • implementation
    • Address of the implementation contract.
  • salt
    • Salt used for the create2 operation.
  • chainId
    • ID of the chain on which the contract is created.
  • tokenContract
    • Address of the token contract.
  • tokenId
    • ID of the token.
  • account
    • Returns the computed account address.

A contract conforming to ERC7656Registry must support 0xc6bdc908, the interface ID of IERC7656Registry.

Building on the principles of ERC-6551, the proposal provides a more flexible way to manage accounts linked to NFTs. The details are described below. Each token-linked account must be deployed as an ERC1167 minimal proxy. This enables efficient, low-cost contract deployment.

Structure of the deployed bytecode

  • ERC-1167 header (10 bytes)
  • Implementation address (20 bytes)
  • ERC-1167 footer (15 bytes)
  • Salt (32 bytes)
  • Chain ID (32 bytes)
  • Token contract address (32 bytes)
  • Token ID (32 bytes)

This structure allows each token-linked account to be uniquely determined and deployed using the specified parameters.

IERC7656Linked interface

Contracts created using ERC7656Registry must implement the IERC7656Linked interface.

js
interface IERC7656Linked {
/**
* @notice Returns the token linked to the contract
* @return chainId The chainId of the token
* @return tokenContract The address of the token contract
* @return tokenId The tokenId of the token
*/
function token() external view returns (uint256 chainId, address tokenContract, uint256 tokenId);
}

The function returns information about the token linked to the contract: its chainId, token contract address, and tokenId. The mechanism also supports contracts implementing the ERC6551Account interface.

Additional details

ERC7656 aims to extend the types of contracts linked to NFTs beyond accounts, making them general-purpose contracts.

General-purpose function and event names

General-purpose names allow different kinds of contracts to be supported, not just accounts. Avoiding restrictions to specific roles or functionality improves flexibility and accommodates a variety of use cases. It also keeps the interface simple and adaptable to different implementations.

Removing the singleton registry requirement

Unlike ERC6551, ERC7656 does not require a registry to be deployed as a single instance. Projects can therefore customize and optimize registries to meet their own requirements and constraints.

Explicit support for the IERC7656Registry interface

Having all registries explicitly support IERC7656Registry enables compatibility with and recognition alongside ERC6551. This makes interactions with conforming registries easier and encourages a consistent, standardized ecosystem.

Flexible contract integration

The proposal is designed to link NFTs not only to accounts but also to other contracts associated with NFTs. This makes it possible to support different NFT use cases, including complex financial products and identity verification systems.

Maintaining compatibility

The proposal is compatible with ERC6551 accounts. This makes migration easier for applications and services built on ERC6551.

Summary

These technical decisions broaden the range of contracts that can be associated with NFTs, provide developers with tools to build new applications, and support the growing ecosystem of decentralized applications. ERC-7656 aims to provide a flexible and robust foundation for future NFT technology by addressing existing limitations and new use cases.

Reference implementations

ERC7656Registry

The ERC7656Registry reference implementation differs from ERC6551Registry in the following ways.

  • General-purpose function names.
  • Different events and errors.
  • Adds a supportsInterface function that returns true only for the relevant interface ID.
js
contract ERC7656Registry is IERC7656Registry {
  function create(
    address implementation,
    bytes32 salt,
    uint256 /* chainId */,
    address tokenContract,
    uint256 tokenId
  ) external override returns (address) {
    // solhint-disable-next-line no-inline-assembly
    assembly {
    // Memory Layout:
    // ----
    // 0x00   0xff                           (1 byte)
    // 0x01   registry (address)             (20 bytes)
    // 0x15   salt (bytes32)                 (32 bytes)
    // 0x35   Bytecode Hash (bytes32)        (32 bytes)
    // ----
    // 0x55   ERC-1167 Constructor + Header  (20 bytes)
    // 0x69   implementation (address)       (20 bytes)
    // 0x5D   ERC-1167 Footer                (15 bytes)
    // 0x8C   salt (uint256)                 (32 bytes)
    // 0xAC   chainId (uint256)              (32 bytes)
    // 0xCC   tokenContract (address)        (32 bytes)
    // 0xEC   tokenId (uint256)              (32 bytes)

    // Copy bytecode + constant data to memory
      calldatacopy(0x8c, 0x24, 0x80) // salt, chainId, tokenContract, tokenId
      mstore(0x6c, 0x5af43d82803e903d91602b57fd5bf3) // ERC-1167 footer
      mstore(0x5d, implementation) // implementation
      mstore(0x49, 0x3d60ad80600a3d3981f3363d3d373d3d3d363d73) // ERC-1167 constructor + header

    // Copy create2 computation data to memory
      mstore8(0x00, 0xff) // 0xFF
      mstore(0x35, keccak256(0x55, 0xb7)) // keccak256(bytecode)
      mstore(0x01, shl(96, address())) // registry address
      mstore(0x15, salt) // salt

    // Compute account address
      let computed := keccak256(0x00, 0x55)

    // If the account has not yet been deployed
      if iszero(extcodesize(computed)) {
      // Deploy account contract
        let deployed := create2(0, 0x55, 0xb7, salt)

      // Revert if the deployment fails
        if iszero(deployed) {
          mstore(0x00, 0xd786d393) // `CreationFailed()`
          revert(0x1c, 0x04)
        }

      // Store account address in memory before salt and chainId
        mstore(0x6c, deployed)

      // Emit the Created event
        log4(
          0x6c,
          0x60,
          0xc6989e4f290074742210cbd6491de7ded9cfe2cd247932a53d31005007a6341a,
          implementation,
          tokenContract,
          tokenId
        )

      // Return the account address
        return(0x6c, 0x20)
      }

    // Otherwise, return the computed account address
      mstore(0x00, shr(96, shl(96, computed)))
      return(0x00, 0x20)
    }
  }

  function compute(
    address implementation,
    bytes32 salt,
    uint256 /* chainId */,
    address /* tokenContract */,
    uint256 /* tokenId */
  ) external view override returns (address) {
    // solhint-disable-next-line no-inline-assembly
    assembly {
    // Copy bytecode + constant data to memory
      calldatacopy(0x8c, 0x24, 0x80) // salt, chainId, tokenContract, tokenId
      mstore(0x6c, 0x5af43d82803e903d91602b57fd5bf3) // ERC-1167 footer
      mstore(0x5d, implementation) // implementation
      mstore(0x49, 0x3d60ad80600a3d3981f3363d3d373d3d3d363d73) // ERC-1167 constructor + header

    // Copy create2 computation data to memory
      mstore8(0x00, 0xff) // 0xFF
      mstore(0x35, keccak256(0x55, 0xb7)) // keccak256(bytecode)
      mstore(0x01, shl(96, address())) // registry address
      mstore(0x15, salt) // salt

    // Store computed account address in memory
      mstore(0x00, shr(96, shl(96, keccak256(0x00, 0x55))))

    // Return computed account address
      return(0x00, 0x20)
    }
  }

  /// @dev Returns true if interfaceId is IERC7656Registry's interfaceId
  /// This contract does not explicitly extend IERC165 to keep the bytecode as small as possible
  function supportsInterface(bytes4 interfaceId) external pure returns (bool) {
    return interfaceId == 0xc6bdc908;
  }
}

IERC7656Linked

contract LinkedContract is IERC7656Linked, EIP5313 {

function token() public view virtual returns (uint256, address, uint256) { bytes memory footer = new bytes(0x60); assembly { extcodecopy(address(), add(footer, 0x20), 0x4d, 0x60) } return abi.decode(footer, (uint256, address, uint256)); }

function owner() public view virtual override returns (address) { (uint256 chainId, address tokenContract_, uint256 tokenId_) = token(); if (chainId != block.chainid) return address(0); return IERC721(tokenContract_).ownerOf(tokenId_); } }

Security

There are no particular additional security considerations beyond those discussed in ERC6551.

Citation

Francesco Sullo (@sullof), "ERC-7656: Generalized Token-Linked Contracts [DRAFT]," Ethereum Improvement Proposals, no. 7656, March 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7656.

Conclusion

This article covered ERC7656, a proposal to extend ERC6551 with a registry for general-purpose contracts linked to specific NFTs. I hope this explanation was helpful.

If you have questions, feel free to reach out via direct message on Twitter.

Twitter @cardene777

I also publish content on other platforms, which you can find below.

https://chaldene.net/