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 ERC6551, a proposal for implementing token-bound accounts that let NFTs behave like Ethereum accounts and hold NFTs and tokens.

The following explanation translates, summarizes, and expands on the material linked below.

At the time of the original article, ERC4337 was described as being in Review. Please note that the specification may change.

Overview

Consider a special type of digital asset known as a non-fungible token (NFT). NFTs are used to uniquely identify individual items, artwork, and other objects online. Historically, however, NFTs have had difficulty interacting with other assets and applications.

This proposal introduces a way to associate Ethereum accounts with NFTs. It allows an NFT itself to act much like an individual user. NFTs can own assets and interact with applications without requiring substantial changes to existing smart contracts or systems.

Consider, for example, a character in a role-playing game. The character may acquire various items and attributes during gameplay. Under this proposal, the character itself can have an Ethereum account through which it owns items and performs in-game actions.

The proposal aims to give every NFT the capabilities of an Ethereum user. This provides a new way for NFTs to represent various complex real-world assets.

Motivation

The ERC721 standard has led to widespread adoption of non-fungible tokens (NFTs). It has enabled a range of interesting use cases, including breedable cats, generative art, and liquidity positions on exchanges.

Historically, however, NFTs have had difficulty acting as autonomous agents or interacting with other on-chain assets. This has made it difficult to represent many types of real-world non-fungible assets as NFTs. Examples include the following.

  • A role-playing game character that develops according to its actions.
  • An automobile made up of fungible and non-fungible parts.
  • An investment portfolio consisting of multiple fungible assets.
  • A punch-pass membership card that provides access to establishments and records past interactions.

Punch-pass membership card This is a card that provides access to a particular location or service and records its usage history.

Establishments such as gyms, cafes, and movie theaters may allow customers to use their services by punching a card on each regular visit. This is known as a punch-pass membership card.

The card typically receives a punch (a stamp or mark) after a specified number of visits or purchases, and collecting enough punches may earn a reward or discount. Because the card also records past usage, it can show how often a customer has visited and which services they have used.

Such cards may be used in loyalty programs and to encourage customer engagement.

The proposal therefore aims to give every NFT the same kinds of capabilities as an Ethereum user. These include the ability to manage assets, the ability to perform arbitrary operations, the ability to control multiple independent accounts, and the ability to use accounts across multiple blockchains. This makes it possible to represent complex real-world assets as NFTs in a common way, using an approach resembling Ethereum's existing ownership model.

The proposal achieves this by defining a singleton registry that assigns unique, deterministic smart contract account addresses to NFTs. Each account is permanently bound to one NFT and controlled by the NFT's holder.

This approach requires no changes to existing NFT smart contracts. It is compatible with virtually every existing system that supports Ethereum accounts, from on-chain protocols to off-chain indexers. Token-bound accounts are compatible with all existing on-chain asset standards and can be extended to support future asset standards.

Giving all NFTs the full functionality of Ethereum accounts opens many new possibilities for both existing and future NFTs.

Specification

At a high level, the proposal consists of two main elements.

  • A singleton registry for token-bound accounts.
  • A common interface for token-bound account implementations. The following diagram shows the relationship among an NFT, its holder, a token-bound account, and the registry.

diagram.png

Source: https://eips.ethereum.org/EIPS/eip-6551

The proposal introduces a mechanism called token-bound accounts. These accounts are associated with NFTs and allow them to own assets and interact with applications. It also provides common interfaces for managing and implementing these accounts. The proposal gives NFTs additional functionality and opens up new possibilities.

Registry

The registry is a system that brings together information about token-bound accounts, the addresses associating tokens with accounts, in one place. It has two primary functions.

  1. createAccount This function creates a token-bound account. Specifically, supplying an implementation address (the address identifying the account implementation to use) creates an account associated with the NFT.

  2. account This function computes a token-bound account's address. It likewise uses the implementation address as part of the calculation of the token-bound account address.

The registry creates and manages token-bound accounts using minimal proxies from the ERC1167 standard. A minimal proxy includes the following data.

yaml
ERC-1167 Header               (10 bytes)
<implementation (address)>    (20 bytes)
ERC-1167 Footer               (15 bytes)
<salt (uint256)>              (32 bytes)
<chainId (uint256)>           (32 bytes)
<tokenContract (address)>     (32 bytes)
<tokenId (uint256)>           (32 bytes)

A minimal proxy containing this data is deployed as each token-bound account. In other words, a dedicated account can be created for an NFT and operate while retaining the necessary information.

This enables token-bound accounts to work with NFTs and manage token-related information effectively.

Consider a concrete example: a token-bound account with the following parameters.

  • Address
    • 0xbebebebebebebebebebebebebebebebebebebebe
  • Salt
    • 0
  • Chain ID
    • 1
  • Token contract address
    • 0xcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcf
  • Token ID
    • 123

Salt A salt (Salt) is a random value used to improve security or randomness. Put simply, it is like adding salt to protect a password.

For example, if multiple users share a password and an attacker analyzes their passwords, the results will all be the same. Introducing a Salt adds different salts even to identical passwords, making the attacker's analysis more difficult.

In the context of this token-bound account, a Salt is used to make account addresses more randomized and less predictable. Combining the other inputs with a Salt can generate different account addresses under otherwise identical conditions, improving security.

The deployed bytecode of this token-bound account's minimal proxy is as follows.

yaml
363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000cfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcf000000000000000000000000000000000000000000000000000000000000007b

This is the deployed bytecode of the minimal proxy used as the token-bound account.

The minimal proxy delegates its operations to a contract implementing the IERC6551Account interface.

The registry contract is permissionless, immutable, and ownerless. The registry is deployed at address TBD using Nick's Factory (0x4e59b44847b379578588920cA78FbF26c0B4956C) and salt 0x6551655165516551655165516551655165516551655165516551655165516551.

The registry also uses the create2 opcode to deploy each account address deterministically. Each token-bound account address is determined by a combination of the implementation address, token contract address, token ID, EIP155 chain ID, and salt.

create2 This is an Ethereum smart contract deployment method whose distinctive opcode allows addresses to be computed deterministically.

Normally, deploying a smart contract involves mining a transaction, as a result of which a new address is assigned. With create2, however, the address can be computed in advance from specified conditions and the contract deployed to that address.

create2 is used as follows.

  1. Prepare the bytecode of the smart contract to deploy and the necessary parameters.
  2. Combine the bytecode, initial salt (an arbitrary random value), and hash function to compute the address of the deployed contract.
  3. Send a transaction deploying the smart contract to the computed address.

This method always produces the same address under identical conditions, allowing address collisions or conflicts to be avoided. Because create2 lets you compute the address in advance, there is no need to wait for transaction mining to determine it, making contract deployment more efficient.

In short, create2 computes an address from specified conditions and deploys a smart contract to that address. This improves address predictability and deployment efficiency.

The registry implements the following interface.

javascript
interface IERC6551Registry {
    event AccountCreated(
        address account,
        address indexed implementation,
        uint256 chainId,
        address indexed tokenContract,
        uint256 indexed tokenId,
        uint256 salt
    );

    function createAccount(
        address implementation,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId,
        uint256 seed,
        bytes calldata initData
    ) external returns (address);

    function account(
        address implementation,
        uint256 chainId,
        address tokenContract,
        uint256 tokenId,
        uint256 salt
    ) external view returns (address);
}

AccountCreated

Overview An event emitted when an account is successfully created.

Parameters

  • account
    • Account address.
  • implementation
    • Implementation address.
  • chainId
    • Chain ID.
  • tokenContract
    • Token contract address.
  • tokenId
    • Token ID.
  • salt
    • Salt (random value).

createAccount

Overview A function that creates a token-bound account for a non-fungible token (NFT).

Details

  • If the account has already been created, return its address without calling create2.
  • If initData is not empty and the account has not yet been created, call account with the supplied initData after creation.
  • Creating the account emits the AccountCreated event.

Parameters

  • implementation
    • Implementation address.
  • chainId
    • Chain ID.
  • tokenContract
    • Token contract address.
  • tokenId
    • Token ID.
  • seed
    • Seed (random value).
  • initData
    • Initialization data.

Return value

  • Account address.

account

Overview A function that returns the computed address of a token-bound account for an NFT.

Details

  • Returns the computed account address.
  • The computation uses the implementation address, chain ID, token contract address, token ID, and salt.

Parameters

  • implementation
    • Implementation address.
  • chainId
    • Chain ID.
  • tokenContract
    • Token contract address.
  • tokenId
    • Token ID.
  • salt
    • Salt (random value).

Return value

  • Computed account address.

Account interface

Implementing ERC165 interface detection

Token-bound account implementations must implement ERC165 interface detection.

Implementing ERC1271 signature validation

Token-bound account implementations must implement ERC1271 signature validation.

Implementing the following interface

Token-bound account implementations must implement the specified interface.

javascript
interface IERC6551Account {
    receive() external payable;

    function token()
        external
        view
        returns (
            uint256 chainId,
            address tokenContract,
            uint256 tokenId
        );

    function state() external view returns (uint256);

    function isValidSigner(address signer, bytes calldata context)
        external
        view
        returns (bytes4 magicValue);
}
receive

Overview A function that allows the account to receive Ether.

Details

  • Implementing this function allows the account to receive Ether sent by other addresses.
  • Arbitrary logic can also be implemented to control the conditions under which Ether is accepted.

token

Overview A function that returns the identifier of the non-fungible token associated with the account. It returns the details of the token associated with the account.

Return values

  • uint256
    • EIP155 chain ID.
  • address
    • Token contract address.
  • uint256
    • Token ID.

state

Overview A function that returns a value that changes whenever the account's state changes.

Details

  • It retrieves a value representing the current state of the account.
  • The value changes whenever the account's state changes.

Return value

  • uint256
    • A value representing the account's state.

isValidSigner

Overview A function that returns a magic value indicating whether a particular signer is authorized to act on behalf of the account.

Details

  • Determines whether a given signer is valid for the account.
  • If the signer is valid, it returns the specified magic value (0x523e3260).
  • By default, the holder of the non-fungible token to which the account is bound is considered a valid signer. Accounts can implement additional authorization logic to grant or revoke signing authority for other accounts.

Parameters

  • signer
    • Signer's address.
  • context
    • Additional data for determining whether the signer is valid.

Return value Returns the magic value (0x523e3260) if the signer is valid.

Execution interface

Token-bound accounts must implement an execution interface that allows valid signers to perform arbitrary operations on behalf of the account. Accounts must indicate support for this execution interface using ERC165 interface detection.

Token-bound accounts may support an execution interface such as the following.

javascript
/// @dev the ERC-165 identifier for this interface is `0x74420f4c`
interface IERC6551Executable {
    /**
     * @dev Executes a low-level operation if the caller is a valid signer on the account
     *
     * Reverts and bubbles up error if operation fails
     *
     * @param to        The target address of the operation
     * @param value     The Ether value to be sent to the target
     * @param data      The encoded operation calldata
     * @param operation A value indicating the type of operation to perform
     *
     * Accounts implementing this interface MUST accept the following operation parameter values:
     * - 0 = CALL
     * - 1 = DELEGATECALL
     * - 2 = CREATE
     * - 3 = CREATE2
     *
     * Accounts implementing this interface MAY support additional operations or restrict a signer's
     * ability to execute certain operations
     *
     * @return The result of the operation
     */
    function execute(
        address to,
        uint256 value,
        bytes calldata data,
        uint256 operation
    ) external payable returns (bytes memory);
}

execute

Overview Allows the caller, if it is a valid signer, to execute a low-level operation on the account.

Details

  • Executes a low-level operation if the caller is a valid signer for the account.
  • If the operation fails, reverts and propagates the error.

Parameters:

  • to
    • Target address of the operation.
  • value
    • Amount of Ether to send to the target.
  • data
    • Encoded calldata for the operation.
  • operation
    • Value indicating the type of operation to perform.

Operation values: Accounts implementing this interface must accept the following operation parameter values.

  • 0 = CALL
  • 1 = DELEGATECALL
  • 2 = CREATE
  • 3 = CREATE2

Accounts may also support additional operations or restrict a signer's ability to execute certain operations.

Return value

Returns the result of the operation.

Executing a low-level operation Suppose you are a valid signer for a token-bound account that holds Ether. Suppose the account wants to execute an operation sending ERC20 tokens to another address.

You can use the execute function to perform the low-level operation. Here is the specific procedure.

  1. Set to to the address of the destination for the token transfer.
  2. Set value to the amount of Ether to send. No Ether is needed in this case, so specify 0.
  3. data Encode the data specifying the token transfer operation. This data consists of the ERC20 token transfer function and its arguments.
  4. operation Specify the value indicating the token transfer operation. An ERC20 token transfer typically uses a CALL operation (operation = 0).

If the account permits the operation, calling execute enables a valid signer to send the tokens. The account receives the details of the token transfer operation and performs the transfer accordingly. If the operation succeeds, the token transfer result is returned.

In this way, execute provides a mechanism for performing operations specified by a valid signer of the account.

Return value It contains information about whether the token transfer succeeded and other relevant information. The exact return value depends on the token implementation and operation used, but may generally include a transaction hash or a success flag.

Rationale

Singleton registry

Theoretical background (rationale)

The proposal introduces the concept of a singleton registry. It defines one common registry that can be deployed permissionlessly at a known address on any chain. Using one registry instead of creating several different registry contracts enables the following important properties.

Counterfactual (predictable) accounts

Token-bound accounts are created using the create2 opcode. This allows an account to exist counterfactually before it is actually created. In other words, the account can receive assets before its contract is deployed. A singleton account registry establishes a common addressing scheme for all token-bound account addresses.

Trust-minimized deployment

A singleton, ownerless registry ensures that account owners need to trust only the account implementation. The account implementation provides the code and logic for performing specific actions. It is responsible for operations and asset management within the account.

For example, suppose a token holder owns an NFT (non-fungible token). This NFT is associated with a particular token-bound account that holds assets. With a singleton, ownerless registry, the account implementation is the trusted component, and all operations within the account are controlled by that implementation.

The token holder can securely manage assets and operations within the account using a trusted account implementation. Because the account implementation supports counterfactual (predictable) accounts, assets can be transferred and operations arranged before the account holding those assets is actually created. This allows the token holder to access assets reliably and securely and use the token-bound account's functionality.

Cross-chain compatibility

A singleton registry with a known address enables each token-bound account to exist on multiple chains. Including chainId among the parameters of createAccount allows the token-bound account contract to be deployed at the same address on any chain. Account implementations can support cross-chain account execution, allowing an NFT on one chain to control a token-bound account on another.

Single entry point

A single entry point for querying account addresses and AccountCreated events makes it easy for applications to retrieve account addresses and creation events. Providing this entry point streamlines the retrieval of information about token-bound accounts.

In particular, applications supporting the proposal do not need to perform complex indexing tasks to find and display account addresses and creation events. Using the single entry point, an application can readily retrieve the addresses and creation events of accounts associated with a particular NFT.

This lets users quickly retrieve and manage account information. Avoiding complex queries and database operations improves application usability and the user experience. As a result, retrieving and managing information associated with token-bound accounts becomes simpler and more efficient.

Implementation diversity

A singleton registry allows different account implementations to generate and manage addresses through a common mechanism. It provides an environment in which developers can readily support various account capabilities and models in client applications.

Consider account-specific capabilities such as delegation or alternative account models such as ephemeral accounts. These capabilities and models may be implemented differently according to the characteristics of the account. However, by providing a common addressing scheme, the singleton registry lets different implementations generate addresses in the same manner and manage accounts through a common mechanism.

This gives developers flexibility in designing and implementing account functionality and characteristics. For instance, an account with delegation functionality can still operate under the same addressing scheme. Likewise, an ephemeral account can be managed through the common addressing scheme, simplifying application-side processing.

In short, a singleton registry lets different account implementations share a common foundation while giving developers freedom to design and implement their accounts. This creates an environment where diverse account capabilities and models can readily be integrated and supported.

Registry vs. factory

The term Registry, rather than Factory, was chosen to emphasize querying account addresses (a frequent operation) rather than creating a particular account (a one-time operation). In other words, the proposal highlights the more important role of querying existing account addresses over account creation.

Flexible execution interfaces

The proposal does not require different accounts to implement a particular execution interface in order to be compatible. Instead, an account can be compatible with the proposal by indicating support for at least one execution interface through ERC165 interface detection.

Account developers are therefore free to choose an execution interface appropriate for their accounts. This supports not only various existing execution interfaces but also new interfaces that may be standardized in the future.

This approach gives account developers the flexibility to select execution interfaces that suit their needs and application requirements, enabling more developers to use the proposal. It also makes it easier to accommodate future changes and new standards as the broader system evolves.

Account ambiguity

The proposal is designed to allow an NFT to have multiple token-bound accounts. During development, however, an alternative assigning one token-bound account to each NFT was considered. Under this alternative, each token-bound account address would be a unique identifier.

There are several considerations with that alternative.

First, the nature of smart contracts makes it impossible to enforce a limit of one token-bound account per NFT. Anyone wishing to associate multiple token-bound accounts with a single NFT could deploy another registry contract.

Second, restricting each NFT to one token-bound account would require a specific, static, trusted account implementation. However, this approach could constrain the functionality of token-bound accounts. Given the many use cases enabled by the proposal and the possibilities that different account implementations offer the NFT ecosystem, it would be premature to define a restrictive standard implementation at this stage.

Finally, the proposal aims to give NFTs the ability to act on-chain. In practice, agents operating on-chain typically use multiple accounts. For example, some individuals use a hot account for everyday activities and a cold account for storing valuable assets. If on-chain agents commonly use multiple accounts, it makes sense to allow NFTs to use multiple accounts as well.

Proxy implementation

ERC1167 minimal proxies are widely used in existing systems and constitute a common smart contract pattern. In this proposal, each token-bound account is created using a specialized ERC1167 proxy. The proxy implementation appends the salt (a random value), chain ID, token contract address, and token ID to the contract bytecode as ABI-encoded constant data.

This approach enables token-bound account implementations to query the data easily. At the same time, the data is guaranteed to remain constant. The method was chosen to maximize compatibility with existing infrastructure while giving smart contract developers sufficient flexibility to create custom token-bound account implementations. In other words, different token-bound account implementations can be created easily and interoperate with other systems.

EIP155 support

The proposal identifies each NFT using its EIP155 chain ID together with its contract address and token ID. Token identifiers are globally unique on a single Ethereum chain, but not necessarily across multiple Ethereum chains.

Backward compatibility

The proposal aims to maximize backward compatibility with existing non-fungible token contracts. It therefore does not extend the ERC721 standard.

In addition, the proposal does not require the registry to check for ERC165 interface support before creating an account. This maximizes compatibility with non-fungible token contracts predating ERC721 (for example, CryptoKitties) and token contracts implementing only part of the ERC721 interface (for example, ENS NameWrapper names). The system described by the proposal can also be used with semi-fungible or fungible tokens, but those use cases are outside its scope.

Smart contract authors may choose to enforce ERC721 interface detection in their own account implementations.

Reference implementations

Example account implementation

Source: https://eips.ethereum.org/EIPS/eip-6551

Registry implementation

Source: https://eips.ethereum.org/EIPS/eip-6551

Security considerations

Fraud prevention

To enable trustless sales of token-bound accounts, decentralized marketplaces need to implement safeguards against fraudulent behavior by malicious account owners.

Consider the following potential fraud scenario:

  1. Alice owns ERC721 token X and its token-bound account Y.
  2. Alice deposits 10 ETH into account Y.
  3. Bob offers to buy token X for 11 ETH through a decentralized marketplace, assuming that the 10 ETH held in the token-bound account will come with it.
  4. Alice withdraws the 10 ETH from the token-bound account and immediately accepts Bob's offer.
  5. Bob receives token X, but account Y is empty.

To mitigate fraud by malicious account owners, decentralized marketplaces should implement protections against such behavior at the marketplace level. Contracts implementing this EIP can also implement certain fraud protections.

32.png

33.png

The following are several fraud-prevention strategies to consider.

1. Attach the current account state to the marketplace order

Include the token-bound account's state in an order on the decentralized marketplace. If the account state changes after the order is placed, the offer is considered invalid. This allows the order to verify the account state and prevent fraud.

2. Attach a list of asset commitments to the order

Add to the order a list of commitments specifying which assets are expected to remain in the token-bound account when the order is fulfilled. If any of the committed assets have been removed from the account when the order is fulfilled after placement, the offer is considered invalid. This safeguard allows the order to protect the committed assets and prevent fraud.

3. Submit the order through an external smart contract

Before submitting an order to the decentralized marketplace, process it through an external smart contract that verifies the order signature. This external smart contract checks the account state and verifies the committed assets. After confirming that the order is safe and legitimate, submit it to the marketplace.

4. Implement a locking mechanism in the account implementation

Introduce a locking mechanism into the token-bound account implementation to prevent assets from being stolen. This prevents a malicious owner from withdrawing assets from the account and improves security.

These security measures are important for fraud prevention. However, fraud prevention is outside the scope of this proposal and needs to be implemented separately by applications and marketplaces.

Ownership cycles

An ownership cycle occurs when a token-bound account owns another token-bound account that in turn owns the first account. This creates a cycle of ownership and introduces the risk that the assets become inaccessible.

Consider a concrete example.

Example

  1. An ERC721 token is transferred to its own token-bound account.
  2. Suppose Alice owns ERC721 token X and its token-bound account Y.
  3. Alice executes a transaction transferring ERC721 token X to token-bound account Y.
  4. However, because token-bound account Y cannot execute a transaction transferring ERC721 token X, both token X and all assets in account Y become inaccessible.

Possibility of ownership cycles

An ownership cycle occurs when one token-bound account owns another token-bound account that in turn owns the first. Such cycles can also occur when several token-bound accounts own one another.

Effects of ownership cycles

When an ownership cycle exists, all assets held within the account become inaccessible. This is because the ownership cycle prevents asset transfer transactions. As a result, the assets cannot be withdrawn and become permanently locked.

Controlling ownership cycles

Ownership cycles can occur in graphs with a depth of 1 or more, and preventing them requires substantial computation. This is outside the scope of the proposal, and application clients and account implementations are encouraged to take measures that limit the risk of ownership cycles.

In other words, ownership cycles can restrict access to assets, and measures are needed to avoid them.

Citation

Jayden Windle (@jaydenwindle), Benny Giang bg@futureprimitive.xyz, Steve Jang, Druzy Downs (@druzydowns), Raymond Huynh (@huynhr), Alanah Lam alanah@futureprimitive.xyz, Wilkins Chung (@wwhchung) wilkins@manifold.xyz, Paul Sullivan (@sullivph) paul.sullivan@manifold.xyz, Auryn Macmillan (@auryn-macmillan), Jan-Felix Schwarz (@jfschwarz), Anton Bukov (@k06a), Mikhail Melnik (@ZumZoom), Josh Weintraub (@jhweintraub) josh@revest.finance, Rob Montgomery (@RobAnon) rob@revest.finance, "ERC-6551: Non-fungible Token Bound Accounts [DRAFT]," Ethereum Improvement Proposals, no. 6551, February 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6551.

Discussion

ERC6551 has attracted attention because giving NFTs smart contract accounts enables wallet-like behavior, including ownership of NFTs and tokens. As discussed in the security section, however, challenges remain. Although the technology is new and still faces challenges, I think the standard has a wide range of potential applications. At the time of writing, the ERC was still in review, so I considered it safer to monitor developments before implementing it until it reached Final status.

It would also be interesting to experiment with implementations using the following articles as references.

Conclusion

This article covered ERC6551, the proposal for token-bound accounts that allow NFTs to behave like Ethereum accounts and hold NFTs and tokens. I hope it was helpful.

If you have any questions, feel free to contact me via Twitter DM using the link below.

Twitter @cardene777