---
eip: 7858
label: ERC-7858
title: Expirable NFTs and SBTs
status: Final
type: Standards Track
category: ERC
created: 2024-01-04
requires: 165, 721
official: https://eips.ethereum.org/EIPS/eip-7858
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7858.md
canonical: https://eips.huatuo.xyz/zh/eip-7858/
lang: zh
tldr: 一个 ERC-721 扩展，为每个 NFT 或灵魂绑定代币设定开始和结束时间（按区块号或时间戳），使会员资格、门票和许可证可以用标准方式过期。
tags: [nft, sbt, expiry, erc721, extension]
---

# ERC-7858: Expirable NFTs and SBTs

> Non-fungible (NFT) and soulbound (SBT) tokens with expiration, supporting time-limited use cases.

**TL;DR:** 一个 ERC-721 扩展，为每个 NFT 或灵魂绑定代币设定开始和结束时间（按区块号或时间戳），使会员资格、门票和许可证可以用标准方式过期。

## 它解决什么问题？

许多代币只应在一段时间内有效：会员资格、订阅、活动门票、许可证、优惠券、租赁、债券。在这个 ERC 出现之前，每个项目都自己构建过期映射。集成方式不一致，自定义的 [ERC-721](/eip-721/) 变体在市场上也可能行为异常。

ERC-7858 在 ERC-721 之上增加了一个标准的过期层，而不改变 NFT 的常规运作方式。过期的代币依然存在，并且（对于 NFT）仍然可以转让；它们只是被报告为无效。

## 它如何运作

基础的 `IERC7858` 接口（ERC-165 ID 为 `0x3ebdfa31`）：

| 成员 | 用途 |
| --- | --- |
| `expiryType()` | `BLOCKS_BASED`（block.number）或 `TIME_BASED`（block.timestamp） |
| `isTokenExpired(tokenId)` | 已过期则返回 `true`；对不存在的代币会 revert |
| `startTime(tokenId)` / `endTime(tokenId)` | 有效期窗口，以区块数或秒为单位 |
| `TokenExpiryUpdated(tokenId, start, end)` | 在铸造时以及窗口每次变化时发出 |

值得记住的规则：

- `balanceOf` 仍然会统计已过期的代币，`transferFrom` / `safeTransferFrom` 对它们也必须仍然可用。
- `startTime <= endTime`。两者都为 `0`，或起始时间非零而 `endTime == 0`，表示**永不过期**。

可选的 `IERC7858Epoch` 扩展（ID 为 `0xec7ffd66`）借鉴了 [ERC-7818](/eip-7818/) 的思路，把代币分组到共享同一有效时长的纪元（epoch）中。它新增了 `currentEpoch`、`epochLength`、`validityDuration`、`isEpochExpired`、`unexpiredBalanceOf` 和 `unexpiredBalanceOfAtEpoch`。

## 示例代码

接口，以及一个只接受未过期通行证的门禁：

```solidity
// 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) { /* ... */ }
}
```

## 需要注意

- **状态：Final。**
- 依赖该代币的合约必须自行调用 `isTokenExpired`；仅靠 ERC-721 的函数无法得知代币已过期。
- 实现必须限制谁能修改 `startTime` / `endTime`，并确保销毁并重新铸造同一个 `tokenId` 不能被用作未经授权的续期。
- 基于区块的过期适合与网络活动挂钩的应用；基于时间的过期适合出块时间不固定的链。
- 相关设计：[ERC-5007](/eip-5007/)（有时间限制的 NFT）、[ERC-4907](/eip-4907/)（带过期时间的租赁用户角色）和 [ERC-7818](/eip-7818/)（可过期的 ERC-20）。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7858
