When you initially create an ERC20 token, you must declare totalSupply
. Is that the hard cap on the number of tokens you can create or is totalSupply
rather just the initial token supply?
2 Answers
No, you can mint as many as you want, which will increase the total-supply (up to 2 ** 256 - 1
).
Make sure that the contract has a mint
function; it is not a part of the ERC20 standard as far as I remember.
You can add this function (or any other function for that matter), so long as you implement the standard itself.
If you are creating an ERC20 token, I suggest you look at inheriting from the OpenZeppelin Contracts ERC20 implementation. See the documentation for details to see if it meets your needs: https://docs.openzeppelin.com/contracts/2.x/tokens
The total supply should match the supply of tokens. If the token allows minting, then when minted the total supply should increase. If the token allows burning, then when burnt, the total supply should decrease.
To create a mintable token you can inherit from OpenZeppelin Contracts ERC20Mintable where you can assign MinterRoles to accounts that can mint. https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#ERC20Mintable
You can also set a cap on the total supply using OpenZeppelin Contracts ERC20Capped https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#ERC20Capped
If you have questions about using OpenZeppelin you can also ask in the Community Forum: https://forum.openzeppelin.com
-
1Thanks a lot for the recommendation. I've heard OpenZeppelin before and will certainly do more research into them in the future in implementing my token. I have accepted @goodvibration answer, as he answered the question first and to my satisfaction, but I've upvoted yours as it is quite helpful in my endeavor as well. Commented Jul 31, 2019 at 15:58
mint
function. It is not necessarily in the ERC20 standard as far as I remember. You can, of course, add this function (or any other function for that matter), so long as you implement the standard itself.