Search code examples
tokenblockchainethereumsoliditytron

increase total supply of TRC20 token daily


I want to issue a token on Tron blockchain and I got it's template from the address below : https://github.com/TRON-Developer-Hub/TRC20-Contract-Template

The problem is that I want to set my token to automatically mint a specified number of tokens daily. (For example mint 2000 tokens per day)

What should I add to the template?


Solution

  • you can add a functionm, below like that. But you have to excute mintDaily() manually

        uint256 constant private dailyMinted = 2000e18;
        uint256 lastMintTime;
    
        address public _owner;
        
        constructor(
            string memory name,
            string memory symbol,
            uint8 decimals,
            address owner
        ) public {
            _name = name;
            _symbol = symbol;
            _decimals = decimals;
    
            _owner = owner;
            lastMintTime = block.timestamp;
        }
        
        function mintDaily() public {
            require(_owner == msg.sender, "not permitted");
            // 24h = 86400
            require(lastMintTime + 86400 >= block.timestamp, "mint already" );
            _mint(msg.sender, dailyMinted);
            lastMintTime = block.timestamp;
        }