Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-2135, an interface for managing consumption of NFTs such as event tickets.

This article translates, summarizes, and expands on the following specification, with assistance from ChatGPT as noted in the original article.

Overview

The proposal defines a standard interface for marking digital assets on Ethereum as consumable and supporting consumption operations. Different types of assets can expose a consistent way to perform consumption and related actions.

Motivation

Some digital assets are consumed when their state changes. A concert ticket, for example, may be considered consumed when its holder enters the venue. Applications need a consistent way to represent this action.

Inconsistent consumption mechanisms can introduce several problems.

Unauthorized consumption

A poorly defined consumption process can increase the risk of fraud or duplicate use, such as consuming the same asset more than once.

Lack of predictability

If consumption conditions differ across implementations, users and contracts may have difficulty predicting asset behavior, potentially causing unexpected results.

Ecosystem fragmentation

Different consumption mechanisms can reduce interoperability among applications and contracts, making integrations more difficult.

Security risks

Inadequate consumption logic can expose assets to unauthorized use or other malicious activity.

Legal and regulatory issues

Some digital assets are subject to legal restrictions or regulatory requirements. Inconsistent handling can make compliance more difficult.

A shared interface enables interoperability among services, clients, user interfaces, and smart contracts. Applications implementing the interface can exchange consumption-related information and invoke common operations more easily.

As blockchain-based asset management evolves, shared interfaces can reduce integration work and support a more cohesive ecosystem.

Specification

Contracts conforming to the proposal implement the following interface.

javascript
pragma solidity >=0.7.0 <0.9.0;

interface IERC2135 {
    function consume(
        address _consumer,
        uint256 _assetId,
        uint256 _amount,
        bytes calldata _data
    ) external returns (bool _success);

    function isConsumableBy(
        address _consumer,
        uint256 _assetId,
        uint256 _amount
    ) external view returns (bool _consumable);
               or future extension.
    event OnConsumption(
        address indexed consumer,
        uint256 indexed assetId,
        uint256 amount,
        bytes data
    );
}

consume

Performs token consumption and returns true when the operation succeeds.

Parameters

  • _consumer
    • The address consuming the token.
  • _assetId
    • The token identifier of the asset being consumed.
  • _amount
    • The quantity consumed.
  • _data
    • Optional additional data.

isConsumableBy

Checks whether the specified asset can be consumed in the requested quantity by the designated consumer. Returns true when consumption is permitted.

Parameters

  • _consumer
    • The address consuming the token.
  • _assetId
    • The token identifier of the asset being consumed.
  • _amount
    • The quantity to consume.

OnConsumption

Emitted when consumption succeeds. Records information about the consumed asset and optional additional data.

Parameters

  • _consumer
    • The address consuming the token.
  • _assetId
    • The token identifier of the consumed asset.
  • _amount
    • The quantity consumed.
  • _data
    • Optional additional data.

Additional specification details

ERC-721 and ERC-1155 define standard interfaces for non-fungible tokens and multi-token management. Implementations using these standards also emit applicable token events when consumption changes token balances or ownership.

For an introduction to ERC-721, see:

https://chaldene.net/erc721

For an introduction to ERC-1155, see:

https://chaldene.net/erc1155

  1. Transfer and TransferSingle events.

ERC-721 emits Transfer for a token ownership change. ERC-1155 emits TransferSingle for a single token ID and amount, while TransferBatch handles multiple token IDs.

  1. OnConsumption event.

ERC-2135 defines OnConsumption to indicate successful consumption.

For ERC-721 or ERC-1155 implementations, the original article describes the following flow when consume succeeds.

  1. Emit OnConsumption to record consumption.
  2. Emit the relevant Transfer or TransferSingle event for the balance or ownership change.
    • The example models consumption as a transfer from the holder to the zero address, representing a burn.

Other contracts and applications can monitor the events and track asset state changes. An application might respond to a user's consumption of an asset by triggering an associated action. Consistent event records support interoperability across the ecosystem.

Additional explanation

The proposal defines a consumption interface without prescribing the conditions or permissions for every consumption operation. This leaves room for different types of assets and use cases.

There are several reasons for this design.

  1. Generality

Consumption conditions and permissions vary by project. A generic interface can accommodate different assets without imposing a single application-specific policy.

  1. Compatibility with ERC-721 and ERC-1155

The interface identifies assets using uint256 IDs, allowing integration with existing token standards that use such identifiers.

  1. Extensibility

Additional functions and events can extend the interface. For example, the _data field allows implementations to carry extra information and support future functionality.

  1. Simple design

The interface does not define asset creation functions or events. Other standards and extensions can provide functionality appropriate to specific creation workflows.

One project may impose particular conditions when creating an asset, while another may require specific attributes or metadata. ERC-2135 focuses on consumption rather than prescribing how every asset must be created.

The interface also does not include asset metadata. A separate extension can add metadata functionality where needed.

Metadata is additional information describing an asset, such as an NFT's description, image, or creator.

ERC-2135 does not directly define metadata operations. Instead, applications can use a separate extension to expose and process metadata according to their needs.

For example, an application may implement a metadata interface to provide additional information about a consumable asset. This keeps the core consumption interface independent of how that information is managed or displayed.

Both consume and isConsumableBy include an address parameter identifying the consumer. This allows the consumer to differ from the transaction initiator.

The interface does not assume that the transaction sender is always the consumer. An application can designate a different address through the consumer parameter.

For example, an ERC-721-based application might allow a designated party to consume an NFT on another person's behalf. Standard ERC-721 transfer permissions ordinarily rely on ownership or approval; the consumption interface makes the consumer explicit rather than requiring the consumer and caller to be identical.

This does not grant unrestricted authority to consume someone else's asset. Implementations must enforce their own authorization rules.

The design supports applications with delegated or otherwise distinct consumption roles.

The interface is intended to accommodate ERC-721, ERC-1155, and other token models, including ERC-20, ERC-777, and fungible ERC-1155 tokens.

Test cases

javascript
describe("Consumption", function () {
    it("Should consume when minted", async function () {
      const fakeTokenId = "0x1234";
      const { contract, addr1 } = await loadFixture(deployFixture);
      await contract.safeMint(addr1.address, fakeTokenId);
      expect(await contract.balanceOf(addr1.address)).to.equal(1);
      expect(await contract.ownerOf(fakeTokenId)).to.equal(addr1.address);
      expect(await contract.isConsumableBy(addr1.address, fakeTokenId, 1)).to.be.true;
      const tx = await contract.consume(addr1.address, fakeTokenId, 1, []);
      const receipt = await tx.wait();
      const events = receipt.events.filter((x: any) => { return x.event == "OnConsumption" });
      expect(events.length).to.equal(1);
      expect(events[0].args.consumer).to.equal(addr1.address);
      expect(events[0].args.assetId).to.equal(fakeTokenId);
      expect(events[0].args.amount).to.equal(1);
      expect(await contract.balanceOf(addr1.address)).to.equal(0);
      await expect(contract.ownerOf(fakeTokenId))
        .to.be.rejectedWith('ERC721: invalid token ID');
      await expect(contract.isConsumableBy(addr1.address, fakeTokenId, 1))
        .to.be.rejectedWith('ERC721: invalid token ID');
    });
  });

  describe("EIP-165 Identifier", function () {
    it("Should match", async function () {
      const { contract } = await loadFixture(deployFixture);
      expect(await contract.get165()).to.equal("0xdd691946");
      expect(await contract.supportsInterface("0xdd691946")).to.be.true;
    });
  });

Reference implementation

The original article identifies a contract deployed on the historical Goerli testnet at address 0x3682bcD67b8A5c0257Ab163a226fBe07BF46379B.

https://goerli.etherscan.io/address/0x3682bcD67b8A5c0257Ab163a226fBe07BF46379B#code

Security considerations

Balance changes during consumption

Implementations must handle balance and ownership changes correctly when assets are consumed. In particular, consumption of a non-fungible token must preserve the token's ownership invariants.

Consistency with pausing and consumption restrictions

When a contract is paused or an account is restricted from transferring tokens, implementations should handle related consumption restrictions consistently. For example, a paused contract may need to prevent consumption as well.

Access control for consume

Implementations must define which EOAs or contract accounts may initiate consumption. Authorization depends on the project's application requirements. Inadequate access controls can permit unauthorized consumption.

Security audits and testing

Review the contract's consumption logic and access controls for security problems. Test the functionality against expected behavior, including invalid callers and repeated consumption attempts.

Addressing these concerns is important for the safety and reliability of compliant contracts. Otherwise, malicious or unauthorized consumption may become possible.

Citation

Zainan Victor Zhou (@xinbenlv), "ERC-2135: Consumable Interface (Tickets, etc)," Ethereum Improvement Proposals, no. 2135, June 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2135.

Conclusion

ERC-2135 provides a common interface for managing consumption of digital assets, including NFTs representing event tickets.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777