ERC-5615 · Final · ERC · 2023-05-25
ERC-5615: ERC-1155 Supply Extension
Adds totalSupply(id) and exists(id) to ERC-1155 multi-token contracts, standardising the supply-tracking helpers that OpenZeppelin already shipped.
What problem does it solve?
ERC-1155 lets one contract hold many token types, each identified by an id. The base standard tells you how much of an id a given account holds, but not how many tokens of that id exist in total, or whether the id is even a real token type.
Marketplaces, explorers and other contracts frequently need those answers: "is this an edition of 100 or of 1?", "has this item been minted yet?". Many implementations, most notably OpenZeppelin's ERC1155Supply, already exposed helper functions for this. ERC-5615 writes that existing practice down as a standard so callers can rely on the same two function signatures everywhere.
How it works
The extension adds two view functions:
| Function | Returns |
|---|---|
totalSupply(uint256 id) |
Number of tokens of that id in circulation; 0 if the id does not exist |
exists(uint256 id) |
Whether the id exists, previously existed, or may exist |
totalSupply deliberately does not revert for unknown ids; it just returns zero. That leaves an ambiguity, since zero supply can mean "nothing minted yet" or "this id will never be used". exists is there to tell those two cases apart, which is why it is phrased loosely ("exists, previously existed, or may exist"): an implementation can return true for an id that is reserved but not yet minted, or one that has been fully burned.
The function names mirror totalSupply in ERC-20 and the existence checks common in ERC-721 contracts.
The ERC intentionally does not define an ERC-165 interface ID requirement. Implementations may advertise support, but callers must not depend on supportsInterface to detect it, because that would break compatibility with the many contracts deployed before the standard was written.
Sample code
Interface plus a minimal tracking pattern inside mint/burn hooks:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC1155Supply {
function exists(uint256 id) external view returns (bool);
function totalSupply(uint256 id) external view returns (uint256);
}
abstract contract SupplyTracking is IERC1155Supply {
mapping(uint256 => uint256) private _supply;
function totalSupply(uint256 id) public view returns (uint256) {
return _supply[id]; // 0 for unknown ids, never reverts
}
function exists(uint256 id) public view virtual returns (bool) {
return _supply[id] > 0; // simplest policy; may be widened
}
function _afterMint(uint256 id, uint256 amount) internal {
_supply[id] += amount;
}
function _afterBurn(uint256 id, uint256 amount) internal {
_supply[id] -= amount;
}
}
Reading supply off-chain (ethers v6):
import { Contract, JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const multi = new Contract(contractAddress, [
"function totalSupply(uint256) view returns (uint256)",
"function exists(uint256) view returns (bool)",
], provider);
const id = 7n;
if (await multi.exists(id)) {
console.log("edition size:", await multi.totalSupply(id));
}
Things to know
- Status is Final. It is designed to be backward compatible with OpenZeppelin's
ERC1155Supply, so many existing contracts already conform. - Don't probe for this extension with
supportsInterface; the spec says consumers must not rely on ERC-165 here. Call the functions directly and handle a revert if the contract lacks them. existsreturningfalsewhiletotalSupplyis0is the clearest signal that an id is unused;existsreturningtruewith zero supply is legal (reserved or fully burned ids).- Supply tracking costs extra storage writes on every mint and burn.