I was playing on the wizard.openzeppelin.com, and ended up with this for a simple mint-able token (till ownership is renounced):
contract MyToken is ERC20, ERC20Burnable, Ownable, ERC20Permit {
constructor(address initialOwner)
ERC20("MyToken", "MTK")
Ownable(initialOwner)
ERC20Permit("MyToken")
{}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
I want to know, that if I want to place a maximum supply cap of 1 million tokens, will the following be the correct addition?
uint256 private constant cap = 1000000 * 10**18;
And the mint function becomes:
function mint(address to, uint256 amount) public onlyOwner {
require(totalSupply() + amount <= cap, "Cap exceeded");
_mint(to, amount);
}
Or am I missing something?