how to create functionality to make NFT burn automatically when its expiry date is reached ? while minting i am storing 2 parameters minted date and number of months to expire , so i want it to burn automatically after expiry date is reached

  • One way to do it would be to modify the function that returns the address of owner to return nothing if the expiration date is reached. Jul 21, 2022 at 12:23

1 Answer 1


To check the time use Chainlink Keepers. Your contract will be able to check if the current date has passed the expiration date. After the condition is met you could call OpenZeppelin's _burn function:

// SPXD-License-Identifier: MIT

pragma solidity ^0.8.8;

import "@chainlink/contracts/src/v0.8/interfaces/KeeperCompatibleInterface.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract NFT is KeeperCompatibleInterface, ERC721 {
    //time is in unix
    //set mintDate and timeTillExpire

    uint256 public currentDate = block.timestamp;
    uint256 public mintDate;
    uint256 public timeTillExpire;
    uint256 public expireDate = mintDate + timeTillExpire;
    uint256 public tokenId = 0;

    //check if it has passed expiration
    function checkUpkeep(bytes memory)
        returns (bool needsUpkeep, bytes memory)
        bool timePassed = (expireDate >= currentDate);
        needsUpkeep = (timePassed);

    //burns token once condition is met
    function performUpkeep(bytes calldata) external override {
        (bool needsUpkeep, ) = checkUpkeep("");
        require(needsUpkeep == true, "Upkeep not needed.");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.