EIPs Explained

ERC-7858 · Final · ERC · 2024-01-04

ERC-7858: Expirable NFTs and SBTs

An ERC-721 extension that gives each NFT or soulbound token a start and end time (by block number or timestamp), so memberships, tickets and licenses can expire in a standard way.

What problem does it solve?

Many tokens should only be valid for a while: memberships, subscriptions, event tickets, licenses, coupons, rentals, bonds. Before this ERC, each project built its own expiry mapping. Integrations were inconsistent, and custom ERC-721 variants could misbehave on marketplaces.

ERC-7858 adds a standard expiry layer on top of ERC-721 without changing how NFTs normally work. Expired tokens still exist and (for NFTs) can still be transferred; they are simply reported as invalid.

How it works

The base IERC7858 interface (ERC-165 id 0x3ebdfa31):

Member Purpose
expiryType() BLOCKS_BASED (block.number) or TIME_BASED (block.timestamp)
isTokenExpired(tokenId) true if expired; reverts for a nonexistent token
startTime(tokenId) / endTime(tokenId) Validity window, in blocks or seconds
TokenExpiryUpdated(tokenId, start, end) Emitted on mint and whenever the window changes

Rules worth remembering:

  • balanceOf still counts expired tokens, and transferFrom / safeTransferFrom must still work on them.
  • startTime <= endTime. Both 0, or a non-zero start with endTime == 0, means no expiration.

An optional IERC7858Epoch extension (id 0xec7ffd66) groups tokens into epochs that share a validity duration, borrowing the idea from ERC-7818. It adds currentEpoch, epochLength, validityDuration, isEpochExpired, unexpiredBalanceOf and unexpiredBalanceOfAtEpoch.

Sample code

Interface plus a gate that only accepts unexpired passes:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC7858 {
    enum EXPIRY_TYPE { BLOCKS_BASED, TIME_BASED }
    event TokenExpiryUpdated(uint256 indexed tokenId, uint256 indexed startTime, uint256 indexed endTime);
    function expiryType() external view returns (EXPIRY_TYPE);
    function isTokenExpired(uint256 tokenId) external view returns (bool);
    function startTime(uint256 tokenId) external view returns (uint256);
    function endTime(uint256 tokenId) external view returns (uint256);
}

interface IERC721Owner {
    function ownerOf(uint256 tokenId) external view returns (address);
}

contract MembersOnly {
    address public immutable pass;
    constructor(address _pass) { pass = _pass; }

    modifier onlyActiveMember(uint256 tokenId) {
        require(IERC721Owner(pass).ownerOf(tokenId) == msg.sender, "not owner");
        require(!IERC7858(pass).isTokenExpired(tokenId), "membership expired");
        _;
    }

    function enter(uint256 tokenId) external onlyActiveMember(tokenId) { /* ... */ }
}

Things to know

  • Status: Final.
  • Contracts that rely on the token must call isTokenExpired themselves; ERC-721 functions alone will not tell you a token is expired.
  • Implementations must restrict who can change startTime / endTime, and make sure burning and re-minting the same tokenId cannot be used as an unauthorized renewal.
  • Block-based expiry suits apps tied to network activity; time-based expiry suits chains with variable block times.
  • Related designs: ERC-5007 (time-bounded NFTs), ERC-4907 (rental user role with expiry) and ERC-7818 (expirable ERC-20).

#nft #sbt #expiry #erc721 #extension

Details

Authors
sirawt (@MASDXI), ADISAKBOONMARK (@ADISAKBOONMARK), parametprame (@parametprame), Nacharoen (@najaroen)
Status
Final
Type
Standards Track / ERC
Created
2024-01-04
Requires

Machine-readable: Markdown · JSON