Created
February 16, 2023 20:05
-
-
Save floatbeta/98fd46601928048d75e1d779ed24bc9b to your computer and use it in GitHub Desktop.
Here's an example smart contract in Lua that burns an NFT after 12 months from the minted date.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Smart contract to burn an NFT after 12 months from the minted date | |
function constructor() | |
state.var { | |
nft = state.nft('nft'), | |
owner = state.address('owner'), | |
minted_date = state.value(), | |
burn_date = state.value() | |
} | |
end | |
function deploy() | |
owner:set(system.get_sender()) | |
minted_date:set(os.time()) | |
burn_date:set(os.time() + 31536000) -- 12 months in seconds | |
nft:initialize('Your NFT', 'YNFT') | |
end | |
function burn_nft() | |
if os.time() >= burn_date:get() then | |
nft:burn(system.get_sender()) | |
else | |
error('NFT cannot be burned yet') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this contract, we use state.nft to create an NFT, and state.address to store the owner's address. We also use state.value to store the minted date and burn date as Unix timestamps.
In the deploy function, we set the owner to the sender of the transaction, and initialize the NFT with a name of 'MoltenChain NFT' and ticker/symbol of 'MCNFT'. We also set the minted date to the current time, and the burn date to 12 months from the minted date.
The burn_nft function checks if the current time is greater than or equal to the burn date, and if so, burns the NFT using nft:burn. If the burn date has not yet been reached, the function throws an error.
This contract can be modified to fit your specific needs, such as changing the NFT name and ticker, or adjusting the burn date.