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-5007, an ERC-721 extension introducing startTime and endTime to support on-chain time management.
This article translates, summarizes, and supplements the material linked below.
Motivation
Some NFTs are intended to be usable only within a specified period.
Conventional ERC-721 NFTs do not define time information through their core interface. Implementing time-based activation or expiration independently can make integrations more complex and introduce additional gas costs.
Some existing ERC-721 implementations already include time-related functionality, but incompatible interfaces make them difficult for third-party platforms to support consistently.
Introducing startTime and endTime allows applications and contracts to determine whether an NFT is currently valid. The interface itself does not automatically enforce all usage restrictions.
Specification
interface IERC5007 /* is IERC721 */ {
function startTime(uint256 tokenId) external view returns (uint64);
function endTime(uint256 tokenId) external view returns (uint64);
}startTime
Returns the time at which an NFT becomes valid.
The function retrieves the start of the validity period for the supplied tokenId as a Unix timestamp.
endTime
Returns the time at which an NFT becomes invalid.
The function retrieves the end of the validity period for the supplied tokenId as a Unix timestamp.
Optional Specification
Implementation of the following interface is optional.
interface IERC5007Composable /* is IERC5007 */ {
function assetId(uint256 tokenId) external view returns (uint256);
function split(
uint256 oldTokenId,
uint256 newToken1Id,
address newToken1Owner,
uint256 newToken2Id,
address newToken2Owner,
uint64 splitTime
) external;
function merge(
uint256 firstTokenId,
uint256 secondTokenId,
address newTokenOwner,
uint256 newTokenId
) external;
}assetId
Returns the asset ID associated with a particular NFT.
An asset ID identifies the underlying asset shared by tokens derived from an existing NFT through splitting or merging.
The function retrieves the asset ID associated with the supplied tokenId.
split
Splits an NFT into two new tokens. The new NFTs share the original NFT's asset ID, while each has its own token ID.
The following conditions apply.
oldTokenIdmust exist.newToken1IdandnewToken2Idmust not exist.newToken1OwnerandnewToken2Ownermust not be the zero address.splitTimemust fall within the original NFT's validity period, at or afterstartTimeand beforeendTime.
merge
Merges two NFTs into a single NFT.
The following conditions apply.
firstTokenIdandsecondTokenIdmust exist.- The
endTimeof the first NFT must match thestartTimeof the second. newTokenOwnermust not be the zero address.newTokenIdmust not exist.
Implementations must also follow the standard's other requirements, including applicable authorization and asset consistency rules.
Additional Notes
The maximum value of uint64 is 18,446,744,073,709,551,615. Interpreted as seconds, this represents approximately 584,942,419,325 years.
A uint256 is less convenient to handle in many mainstream programming languages, including C, C++, Java, and Go. A 64-bit integer is more widely supported, although signedness and language-specific integer representations must still be considered.
Backward Compatibility
The standard is designed to be compatible with ERC-721.
Test Cases
The following file and commands can be used to run the tests.
cd ../assets/eip-5007
npm install truffle -g
npm install
truffle testhttps://eips.ethereum.org/assets/eip-5007/test/test.js
const { assert } = require("chai");
const { BigNumber } = require("bignumber.js")
const ERC5007Demo = artifacts.require("ERC5007Demo");
const ERC5007ComposableTest = artifacts.require("ERC5007ComposableTest");
contract("test ERC5007", async accounts => {
it("test ERC5007", async () => {
const Alice = accounts[0];
const instance = await ERC5007Demo.deployed("ERC5007Demo", "ERC5007Demo");
const demo = instance;
let now = Math.floor(new Date().getTime()/1000);
let inputStartTime1 = new BigNumber(now - 10000);
let inputEndTime1 = new BigNumber(now + 10000);
let id1 = 1;
await demo.mint(Alice, id1, inputStartTime1.toFixed(0), inputEndTime1.toFixed(0));
let outputStartTime1 = await demo.startTime(id1);
let outputEndTime1 = await demo.endTime(id1);
assert.equal(inputStartTime1.comparedTo(outputStartTime1) == 0 && inputEndTime1.comparedTo(outputEndTime1) == 0, true, "wrong data");
console.log("IERC5007 InterfaceId:", await demo.getInterfaceId())
let isSupport = await demo.supportsInterface('0x7a0cdf92');
assert.equal(isSupport, true , "supportsInterface error");
});
it("test ERC5007Composable", async () => {
const Alice = accounts[0];
const Bob = accounts[1];
const Carl = accounts[2];
const instance = await ERC5007ComposableTest.deployed("ERC5007ComposableTest", "ERC5007ComposableTest");
const demo = instance;
let now = Math.floor(new Date().getTime()/1000);
let token1InputStartTime = new BigNumber(now - 10000);
let token1InputEndTime = new BigNumber(now + 10000);
let id1 = 1;
let assetId = 1000;
console.log("mint NFT:")
await demo.mint(Alice, id1, assetId, token1InputStartTime.toFixed(0),
token1InputEndTime.toFixed(0));
let token1OutputStartTime = new BigNumber( await demo.startTime(id1));
let token1OutputEndTime = new BigNumber( await demo.endTime(id1));
let token1assetId = new BigNumber( await demo.assetId(id1));
assert.equal(token1InputStartTime.comparedTo(token1OutputStartTime) == 0
&& token1InputEndTime.comparedTo(token1OutputEndTime) == 0
&& token1assetId.comparedTo(assetId) == 0,
true, "wrong data");
let id2 = 2;
let id3 = 3;
let splitTime = token1InputStartTime.plus(5000);
console.log("split NFT:")
await demo.split(id1, id2, Bob, id3, Carl, splitTime.toFixed(0));
let token2StartTime = new BigNumber( await demo.startTime(id2));
let token2EndTime = new BigNumber( await demo.endTime(id2));
let token3StartTime = new BigNumber( await demo.startTime(id3));
let token3EndTime = new BigNumber( await demo.endTime(id3));
assert.equal(token1InputStartTime.comparedTo(token2StartTime) == 0
&& token2EndTime.comparedTo(splitTime) == 0, true, "wrong data");
assert.equal(token3StartTime.comparedTo(splitTime.plus(1)) == 0
&& token3EndTime.comparedTo(token1InputEndTime) == 0, true, "wrong data");
let token2assetId = await demo.assetId(id2);
let token3assetId = await demo.assetId(id3);
assert.equal(token2assetId == assetId && token3assetId == assetId, true, 'wrong data');
console.log("merge NFT:")
let id4 = 4;
await demo.setApprovalForAll(Alice, true,{from: Bob});
await demo.setApprovalForAll(Alice, true,{from: Carl});
await demo.merge(id2, id3, Alice, id4);
let token4StartTime = new BigNumber( await demo.startTime(id4));
let token4EndTime = new BigNumber( await demo.endTime(id4));
let token4assetId = await demo.assetId(id4);
let token4Owner = await demo.ownerOf(id4);
assert.equal(token1InputStartTime.comparedTo(token4StartTime) == 0
&& token4EndTime.comparedTo(token1InputEndTime) == 0, true, "wrong start time or end time");
assert.equal(token4assetId == assetId, true, 'wrong rootId');
assert.equal(token4Owner == Alice, true, 'wrong owner');
console.log("IERC5007Composable InterfaceId:", await demo.getInterfaceId())
let isSupport = await demo.supportsInterface('0x75cf3842');
assert.equal(isSupport, true , "supportsInterface error");
});
});Reference Implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IERC5007.sol";
abstract contract ERC5007 is ERC721, IERC5007 {
struct TimeNftInfo {
uint64 startTime;
uint64 endTime;
}
mapping(uint256 => TimeNftInfo) internal _timeNftMapping;
/**
* @dev See {IERC5007-startTime}.
*/
function startTime(uint256 tokenId)
public
view
virtual
override
returns (uint64) {
require(_exists(tokenId), "ERC5007: invalid tokenId");
return _timeNftMapping[tokenId].startTime;
}
/**
* @dev See {IERC5007-endTime}.
*/
function endTime(uint256 tokenId)
public
view
virtual
override
returns (uint64) {
require(_exists(tokenId), "ERC5007: invalid tokenId");
return _timeNftMapping[tokenId].endTime;
}
/**
* @dev mint a new time NFT.
*
* Requirements:
*
* - `tokenId_` must not exist.
* - `to_` cannot be the zero address.
* - `endTime_` should be equal or greater than `startTime_`
*/
function _mintTimeNft(
address to_,
uint256 tokenId_,
uint64 startTime_,
uint64 endTime_
) internal virtual {
require(endTime_ >= startTime_, 'ERC5007: invalid endTime');
_mint(to_, tokenId_);
TimeNftInfo storage info = _timeNftMapping[tokenId_];
info.startTime = startTime_;
info.endTime = endTime_;
}
/**
* @dev Destroys `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*
*/
function _burn(uint256 tokenId) internal virtual override {
super._burn(tokenId);
delete _timeNftMapping[tokenId];
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override
returns (bool) {
return
interfaceId == type(IERC5007).interfaceId ||
super.supportsInterface(interfaceId);
}
}Conclusion
ERC-5007 extends ERC-721 with startTime and endTime to support standardized on-chain validity periods.
I plan to add more implementation details in the future.
If you have questions, feel free to contact me on Twitter.

