I want to mint tokens on a time basis.
Eg: 1,000,000 tokens will be mint this year (1-Sep-2021)
1,000,000 tokens will be mint next year (1-Sep-2022)
and 1,000,000 tokens will mint on 1-Sep-2023.
How can I do that in the ERC-20 contract?
You can write a mint function that checks block timestamps.
A very basic example:
pragma solidity ^0.8.0;
contract TimeLockedMint {
uint alreadyMinted = 0;
uint constant FIRST_MINTING_DATE = 1630454400; 1 Sep 2021
uint constant SECOND_MINTING_DATE = 1661990400; 1 Sep 2022
uint constant FIRST_MINTING_AMOUNT = 1;
uint constant SECOND_MINTING_AMOUNT = 2; // Accumulated.
function mint() public {
if(block.timestamp > SECOND_MINTING_DATE) _mint(SECOND_MINTING_AMOUNT - alreadyMinted);
else if(block.timestamp > FIRST_MINTING_DATE) _mint(FIRST_MINTING_AMOUNT - alreadyMinted);
else revert('No more tokens can be minted');
}
function _mint(uint amount) internal{
alreadyMinted += amount;
// Do actual minting here
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.