ERC-5409 · Stagnant · ERC · 2022-07-23
ERC-5409: EIP-1155 Non-Fungible Token extension
Adds an ERC-721-style ownerOf(tokenId) to ERC-1155 contracts, so callers can find the single owner of a token that is truly non-fungible, or get the zero address if it isn't.
What problem does it solve?
ERC-1155 can hold both fungible and non-fungible tokens in one contract, but it only exposes balanceOf(owner, id). There is no standard way for another contract to ask "is this ID unique, and who owns it?" ERC-1155 mentions a split-ID convention for NFTs, but that is an informal agreement, not part of the interface.
ERC-721 answers that question with ownerOf(tokenId). ERC-5409 brings just that one function to ERC-1155, so NFT-aware tools can work with ERC-1155 NFTs without the contract also implementing the full (less efficient) ERC-721.
How it works
One function:
interface IERC1155OwnerOf {
function ownerOf(uint256 tokenId) external view returns (address);
}
- Returns the unique owner if
tokenIdis an NFT (supply of exactly one owner). - Returns
address(0)if the token does not exist or is not an NFT (its supply could exceed 1). Unlike ERC-721, it does not revert. - May be
vieworpure. supportsInterface(0x6352211e)must returntrue(ERC-165). That ID equals theownerOf(uint256)selector, the same value used inside ERC-721's interface.
Sample code
An ERC-1155 that mints one-of-one tokens and tracks owners (OpenZeppelin v5):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
contract Unique1155 is ERC1155 {
mapping(uint256 => address) private _owner;
uint256 public nextId;
constructor() ERC1155("ipfs://example/{id}.json") {}
function mint() external returns (uint256 id) {
id = nextId++;
_mint(msg.sender, id, 1, "");
}
function ownerOf(uint256 id) external view returns (address) {
return _owner[id]; // zero if unknown
}
function _update(address from, address to, uint256[] memory ids, uint256[] memory values)
internal override
{
super._update(from, to, ids, values);
for (uint256 i; i < ids.length; ++i) if (values[i] == 1) _owner[ids[i]] = to;
}
function supportsInterface(bytes4 id) public view override returns (bool) {
return id == 0x6352211e || super.supportsInterface(id);
}
}
Things to know
- Status is Stagnant; the spec's security section still reads "Needs discussion".
- The sample assumes every ID has a supply of exactly 1. If a contract mixes fungible IDs,
ownerOfmust returnaddress(0)for them. - Callers must treat
address(0)as "no single owner", not as an error; code written for ERC-721 that expects a revert on unknown IDs needs adjusting. - Interface ID
0x6352211eonly provesownerOfexists; it does not mean the contract implements ERC-721.