I want to create a nft ERC721 that after 30 days it will be autoburned. How I can achive this?
3 Answers
You can't have scheduled events/code on Ethereum. My suggestion would be to have a public function that can be called by anybody which will burn the nft. Although you will have to figure out how to incentivize people to call this function.
- 151
- 6
There are two problems you need to address here:
- running a 30-day timer in a smart contract, and
- burning a token automatically (the answer to which depends on what you mean by "burning")
Running a 30-day timer in a smart contract
There is no inherent primitive of scheduling in Ethereum. You need a work-around for this. The easiest way to do this would probably be to set up some sort of cron on a server to call a burn function in your smart contract when the time is up. You'd probably want to guard against premature calls by using Solidity's block.timestamp to get the timestamp of the transaction being executed and checking against that.
Burning a token automatically
Depending on what you mean by "burning" here, you can implement custom logic that will manipulate the token in the smart contract (e.g. transfer it). You probably don't need to do anything fancy here.
- 463
- 2
- 10
What you can do is start a timer inside the constructor of your smart contract. Every time mint is called if statement is required to check if 30 days have been passed. If so, burn the NFT. Something like this:
constructor() {
auction_timer = block.timestamp;
auction_end_time = auction_timer + 30 days;
}
function mint() {
if (auction_end_time > block.timestamp) {
// burn
}
}
But unfortunately, unless you build automated server to call this, there is not way to fully automate. Someone has to call this func!
- 1,654
- 2
- 9
- 24