Last active
August 11, 2023 18:53
-
-
Save valterlobo/53beb1d079b0f14a15dbfb82bf47bf94 to your computer and use it in GitHub Desktop.
Caso esteja utilizando a lib openzenzepelin veja a implementação da extensão ERC20Capped.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity 0.8.18; | |
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | |
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol"; | |
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract MyToken is ERC20Capped, Ownable, ERC20Burnable { | |
constructor(uint256 cap, uint256 initialSupply) | |
ERC20("MYTK", "MTK") | |
ERC20Capped(cap * 10**18) | |
{ | |
require(initialSupply <= cap, "TOKEN Capped: limit exceeded"); | |
//default 18 decimals ERC20 | |
ERC20._mint(msg.sender, initialSupply * 10**18); | |
} | |
//lembre-se : mint 18 decimals | |
function mint(address to, uint256 amount) public onlyOwner { | |
_mint(to, amount); | |
} | |
function _mint(address to, uint256 amount) | |
internal | |
override(ERC20, ERC20Capped) | |
{ | |
require( | |
ERC20.totalSupply() + amount <= cap(), | |
"TOKEN Capped: limit exceeded" | |
); | |
super._mint(to, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment