I use OpenZeppilin ERC20Mintable contract and add MaxSupply parameter to contraint the ERC20 token amount allowed to issue.

what I want is only permit contract ower to view MaxSupply info, my function is below:

uint256 MaxSupply;//contract static variable
// self defined function
function ViewMaxSupply() public view onlyMinter return(uint256) {
 return ( MaxSupply* (10 ** uint256(decimals)) );

decimals is equal to 18.

I found when I use onlyMiner modifier, the return value is a very strange number: 3963877391197344453575983046348115674221700746820753546331534351508065746944. when not use modifier onlyMinter, the result is correct: 100000000000000000000

How to fix the error? Thanks.

  • How do you invoke ViewMaxSupply? Since it is a view function it doesn't use from so it might be failing and the call doesn't detect it as an invalid answer. – Ismael Aug 13 '19 at 15:17
  • Perhaps submit as an issue on Github? Make sure to mention your Solidity version. – Ivan P Aug 13 '19 at 15:43
  • @Ismael , I call it by var MaxIssueAmount = await contract.methods.ViewMaxSupply().call(); – Ntydrm Aug 14 '19 at 1:07
  • @Ivan P OK, my solidity version is >npm ls solc solc@0.5.9 , the compiler version in .sol file(pragma solidity ^0.5.0) is lower, I make no modification. – Ntydrm Aug 14 '19 at 1:17
  • @Ntydrm Try passing a minter address as from parameter, like this var MaxIssueAmount = await contract.methods.ViewMaxSupply().call({ from: "0xVALID_ADDRESS" }). – Ismael Aug 14 '19 at 12:28

Answered in the OpenZeppelin Community Forum https://forum.openzeppelin.com/t/erc20mintable-contract-application-returns-a-strange-wrong-number/1178/2

To have a mintable token with a capped (maximum) supply you can use OpenZeppelin ERC20Capped https://docs.openzeppelin.com/contracts/2.x/api/token/erc20#ERC20Capped

Adding a modifier to view the MaxSupply only prevents other contracts from reading the value, but it is visible externally.

https://solidity.readthedocs.io/en/latest/contracts.html?highlight=private#visibility-and-getters Everything that is inside a contract is visible to all observers external to the blockchain. Making something private only prevents other contracts from reading or modifying the information, but it will still be visible to the whole world outside of the blockchain.

If you have questions on using OpenZeppelin you can ask in the Community Forum: https://forum.openzeppelin.com/

Disclosure: I am the Community Manager at OpenZeppelin

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.