EIPs Explained

ERC-5050 · Stagnant · ERC · 2021-04-18

ERC-5050: Interactive NFTs with Modular Environments

A messaging protocol that lets NFTs send typed 'actions' to each other (attack, cast, feed…), optionally settled by a shared state contract, so games and apps can build interoperable 'digital physics' on top of tokens.

What problem does it solve?

ERC-721 and ERC-1155 define what an item is, not what it can do. Projects that want NFTs to interact, such as a sword hitting a monster or a spell cast on a character, each build bespoke contracts, so items from different projects cannot interact, and off-chain apps cannot discover what is possible.

ERC-5050 standardises how one token sends an action to another, how contracts advertise the actions they support, and how a shared "environment" contract can hold the resulting game state.

How it works

  • Action struct. An action has a selector (bytes4(keccak256("namespace.action"))), the user, a from object and a to object (each address + tokenId), an optional state contract and free-form data.
  • Sender interface (IERC5050Sender, ID 0xc8c6c9f3): sendAction(action), isValid(hash, nonce), sendableActions() (human-readable list), plus per-action approvals (approveForAction, setApprovalForAllActions).
  • Receiver interface (IERC5050Receiver, ID 0x1a3f02f4): onActionReceived(action, nonce) and receivableActions().
  • Flow. The sending contract stores a nonced hash of the action and calls the receiver, which may forward it to the state contract. The state contract calls back isValid on the sender to confirm the action is authentic, then finalises it. Without a state contract, sender and receiver manage their own state.
  • State contracts are swappable environments (e.g. a FightGame that stores HP and strength). The same NFTs can play in different environments.
  • Naming conventions: dot for namespaces (spells.cast), > for required sequence (settle>build).
  • Extensions: interfaceURI(action) for custom UIs, action proxies via a modified ERC-1820 registry for legacy contracts, trusted controllers for bridging, and ERC-4906 events for metadata refresh.

Sample code

Sending an action from TypeScript (ethers v6):

import { Contract, id } from "ethers";

const sender = new Contract(fightersAddr, [
  "function sendAction((bytes4 selector,address user,(address _address,uint256 _tokenId) from,(address _address,uint256 _tokenId) to,address state,bytes data) action) payable",
  "function sendableActions() view returns (string[])",
], signer);

console.log(await sender.sendableActions()); // e.g. ["fight.attack"]

await sender.sendAction({
  selector: id("fight.attack").slice(0, 10),        // bytes4 of keccak256
  user: await signer.getAddress(),
  from: { _address: fightersAddr, _tokenId: 1n },
  to:   { _address: monstersAddr, _tokenId: 7n },
  state: fightGameAddr,                              // or ZeroAddress
  data: "0x",
});

Things to know

  • Status: Stagnant; it was never finalised.
  • Validation proves the action came from the initiating contract, not that the user field is honest. The protocol deliberately treats the sending contract as the "prime mover", so only interact with trusted sender contracts.
  • Action chains (sender → receiver → state) can run out of gas; handlers should be minimal and avoid loops.
  • Existing non-upgradeable NFT contracts need a proxy registry to participate.

#nft #gaming #interoperability #erc721 #erc1155

Details

Authors
Alexi (@alexi)
Status
Stagnant
Type
Standards Track / ERC
Created
2021-04-18
Requires

Machine-readable: Markdown · JSON