我想在Tron区块链上发行一个令牌,我从下面的地址得到了它的模板:https://github.com/TRON-Developer-Hub/TRC20-Contract-Template
问题是我想将我的令牌设置为每天自动生成指定数量的令牌。(例如每天铸造2000代币)
我应该在模板中添加什么?
您可以添加一个函数,如下所示。但是你必须手动执行mintDaily()
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;
}