ERC-2135 · Final · ERC · 2019-06-23
ERC-2135: Consumable Interface (Tickets, etc)
A minimal interface for marking NFTs or multi-tokens as consumable, such as event tickets, with a standard consume() call, a pre-check and an OnConsumption event.
What problem does it solve?
Many digital assets are meant to be used up: a concert ticket is "consumed" at the door, a voucher when it is redeemed, a pass when it is scanned. Without a standard, every ticketing contract invents its own redeem, use or checkIn function, so scanners, wallets, marketplaces and other contracts cannot handle them generically.
ERC-2135 defines one small interface for consumption that sits on top of ERC-721 or ERC-1155 tokens.
How it works
A compliant contract implements:
| Member | Purpose |
|---|---|
consume(consumer, assetId, amount, data) |
Consume amount of assetId on behalf of consumer; returns bool |
isConsumableBy(consumer, assetId, amount) |
View check: could this consumption succeed? |
event OnConsumption(consumer, assetId, amount, data) |
Emitted on every successful consumption |
Rules:
supportsInterface(0xdd691946)must returntrue(ERC-165).- If the contract is an ERC-721 or ERC-1155 token, a successful
consumemust also emitTransfer/TransferSingleas if the token moved from the holder to the zero address, so indexers see it disappear. consumerdoes not have to be the transaction sender, so a venue's gate contract or a relayer can consume on someone's behalf.datais free-form for extensions such as signed endorsements.
The standard deliberately says nothing about who may consume, under what conditions, how consumables are created, or what metadata they carry. Those are left to the application.
Sample code
An ERC-721 ticket that only the venue's gate can consume (OpenZeppelin v5):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
interface IERC2135 {
function consume(address consumer, uint256 assetId, uint256 amount, bytes calldata data)
external returns (bool);
function isConsumableBy(address consumer, uint256 assetId, uint256 amount)
external view returns (bool);
event OnConsumption(address indexed consumer, uint256 indexed assetId, uint256 amount, bytes data);
}
contract Ticket is ERC721, IERC2135 {
address public immutable gate;
constructor(address gate_) ERC721("Concert Ticket", "TIX") { gate = gate_; }
function mint(address to, uint256 id) external {
require(msg.sender == gate, "only gate");
_mint(to, id);
}
function isConsumableBy(address consumer, uint256 id, uint256 amount) public view returns (bool) {
return amount == 1 && _ownerOf(id) == consumer;
}
function consume(address consumer, uint256 id, uint256 amount, bytes calldata data)
external returns (bool)
{
require(msg.sender == gate, "only gate");
require(isConsumableBy(consumer, id, amount), "not consumable");
_burn(id); // emits Transfer(owner, address(0), id) as the spec requires
emit OnConsumption(consumer, id, amount, data);
return true;
}
function supportsInterface(bytes4 interfaceId) public view override returns (bool) {
return interfaceId == type(IERC2135).interfaceId || super.supportsInterface(interfaceId);
}
}
Things to know
- Access control is the main security decision. Decide explicitly whether holders, the issuer, or a gate contract may call
consume, and test it. - Keep consumption consistent with transfer restrictions: if transfers are paused or a user is restricted, consumption should behave the same way.
- For ERC-721 and ERC-1155 tokens the required transfer-to-zero event means consumption effectively removes the token from the holder's balance, so burning is the natural implementation.
- The authors note it can be adapted to fungible tokens such as ERC-20, but the interface was designed with NFTs in mind.