2

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 rather just the initial token supply?

  • 2
    No, you can mint as many as you want, which will increase the total-supply (up to 2 ^ 256 - 1). – goodvibration Jul 29 '19 at 18:14
  • 1
    Okay great. I think I misunderstood the purpose of declaring total supply upon deploying a contract. I thought that was the hard cap, but from what you've said, that's just going to set the initial supply, which can always be added to. Thanks! – lustig Jul 29 '19 at 19:54
  • 1
    Make sure that the contract has a 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. – goodvibration Jul 29 '19 at 19:55
  • 2
    Ah, perfect, thank you. Do you want to add this as an answer and I can accept it? – lustig Jul 29 '19 at 20:40
  • 2
    and make sure you add a modifier to the mint function that allows only the owner of the contract to mint it – Samuel Dare Jul 29 '19 at 21:10
3

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.

| improve this answer | |
2

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

| improve this answer | |
  • 1
    Thanks 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. – lustig Jul 31 '19 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.