ERC-5050 NFT Interaction Action Protocol (Interactive NFTs with Modular Environments)

Stagnant · NFTs & multi-token · created 2021-04-18

This standard defines a common messaging format for exchanging user initiated "actions" between tokens such as NFTs, making it possible for anyone to build interoperable, game like logic in which tokens interact with each other and share state.

Why it is needed

Token standards such as EIP-721 and EIP-1155 only express ownership, and do not define how to transmit or process interactions between tokens, such as attacks, duels, or combinations. As a result, every game or digital identity project that wanted to implement inter-token interactions had to build actions in its own way, and wallets or aggregation services had no way to automatically discover which contracts supported which interactions. In addition, when an interaction required shared state, such as hit points in a combat game, there was no standardized way to decide which contract would manage that state or how both sides could verify it in a trustworthy way, forcing each project to design this from scratch.

What to implement

In depth

The Action struct and how it is sent

The Action struct consists of selector (bytes4(keccak256(action_key))), user (sender address), from/to (Object struct: _address and _tokenId), state (state contract address), and data (free form bytes). When sendAction() is called, fromContract is automatically filled with the sending contract's address (address(this)), and the from field is filled with msg.sender. The action starts at the sending contract and is passed in order to the contract specified by to, and then, if specified, to the state contract.

Hash and nonce based verification

When an action passes through all three contracts, fromContract, to, and state, the state contract requests verification from the sending contract via isValid(hash, nonce). Before starting to process the action, the sending contract computes a hash of the action that includes the nonce and records it in storage, and the state contract computes the same hash from the action it received and checks it along with the nonce. This approach was chosen instead of a signed message to avoid both the UX burden of requiring the user to perform a separate signature and a separate transaction submission, and the gas cost of signature verification.

A design that treats the sending token as a trusted party

This standard openly acknowledges the limitation that, aside from tx.origin, the receiving and state contracts have no way to directly verify the sending account. Instead, it treats the sending contract (token) as the "prime mover," leaving it up to the receiving contract's policy to decide which actions to accept and how to process them. High value actions can be restricted in the state contract based on reputation, or access can be limited with allow/deny lists, and the Controllable extension allows a trusted controller to process the action chain on the sender's behalf instead.

The role of the State Contract

Using a state contract for an action is not mandatory; between token contracts, or between a user and a single token contract, each side only needs to manage its own state. On the other hand, specifying a state contract allows arbitrary sending and receiving contracts to share a single state environment designated by the user. Each Object can have its own action processing logic, but final confirmation of an action must always be handled by the state contract, making the state contract the "source of truth." A receiving contract can force the use of a specific state contract, provide a default that the token holder can change, or use it as a bridge connected to a state contract on another chain.

Action naming convention and selectors

Actions are advertised as human readable strings (e.g. "spells.cast"), while actual processing uses a selector obtained by taking the keccak256 hash of that string and using its first 4 bytes. A dot (.) separates namespaces (e.g. the "cast" action in the "spells" namespace), and an arrow (>) specifies ordering (e.g. "settle>build" means settle must be received before build). sendableActions() and receivableActions() return this list of strings so that off-chain services can parse supported features.

The Controllable extension

The Controllable extension allows a trusted controller address to force action processing while bypassing EIP-5050's standard validity checks. setControllerApproval()/setControllerApprovalForAll() approve a controller for a specific action or for all actions; a contract that supports a controller must ignore validation related require/revert statements and must not pass the action on to the next contract in the chain. This can be used for backward compatibility with existing, non-upgradeable deployed contracts, or for cross-chain action bridging.

Backward compatibility and metadata updates

Token contracts that are already deployed and cannot be upgraded are incompatible with this standard unless they use the proxy registry extension. The proxy can be implemented by adapting the EIP-1820 registry so that the EIP-173 contract owner can call setManager(). In addition, an NFT whose metadata changes as a result of an interaction can also implement the EIP-4906 event emitter to announce the change.

A proposal still stalled

This ERC's status is Stagnant, meaning the proposal is no longer actively progressing. Its content may change or may never be adopted.

Things to watch out for

Original ERC · ← ERCs