ERC777 hardcoded values

So I recently discovered ERC777 and I would like to use it ( and more specifically the contract which supports both ERC777 and ERC20 located at https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC777/ERC777.sol )

I was wondering why the the constructor of the provided example does not have the other options like totalSupply, decimals, granularity, etc? I can see only name_, symbol_ and defaultOperators_.

I don’t get why decimals and granularity are hardcoded, what if I want my contract to not support any decimals? I have to edit the openzeppelin lib contract?

Thanks in advance for the clarification!

Ok so this is what I found from the docs:

ERC-20 compatibility requirement :
The decimals of the token MUST always be 18 . For a pure ERC777 token the ERC-20 decimals function is OPTIONAL, and its existence SHALL NOT be relied upon when interacting with the token contract. (The decimal value of 18 is implied.) For an ERC-20 compatible token, the decimals function is REQUIRED and MUST return 18 . (In ERC-20, the decimals function is OPTIONAL. If the function is not present, the decimals value is not clearly defined and may be assumed to be 0 . Hence for compatibility reasons, decimals MUST be implemented for ERC-20 compatible tokens.)

So it seems like if you want to support both ERC777 and ERC20 it’s a must for the token to support decimal values.

But then I still do not understand why the totalSupply is not added to the constructor?

totalSupply is increased automatically whenever you mint new tokens:

So there’s no need to set it to a fixed value in the constructor. If you want to have an initial supply at deployment time, then you can inherit from ERC777 to call _mint on the constructor of your contract.

Thank you again, correct me if I’m wrong, but if we want to have static totalSupply, can’t we just remove the mint and burn methods and then define the total totalSupply in the constructor?

I will ask my question this way - is it required for a contract which is supporting both ERC20 and ERC777 to have burn and mint methods and if yes, why?

Not at all! Note that mint in OpenZeppelin’s ERC20/777 is internal, so you can decide whether you call it internally for setting up total supply, or whether you make it a public method and appoint a minter to call it.

Check out this article which covers exactly this topic: https://docs.openzeppelin.com/contracts/4.x/erc20-supply

1 Like