1

I've deployed an ERC20 token on the main net that you can find on etherscan.io.

The problem I'm having, as you can see on etherscan, is that totalSupply always returns 0, even if I've already minted 6M+ tokens.

This is the ABI for the totalSupply function:

[{
  "constant": true,
  "inputs": [],
  "name": "totalSupply",
  "outputs": [
    {
      "name": "",
      "type": "uint256"
    }
  ],
  "payable": false,
  "stateMutability": "view",
  "type": "function"
}]

Defined in Solidity as:

uint256 public totalSupply;

and initialised in the main contract with:

uint256 public totalSupply = 0;

I don't understand if totalSupply is correctly stored internally and it's just a problem when getting the value from outside, or if the smart contract is actually not adding the minted tokens to the totalSupply.

Any help is appreciated.

EDIT: this is the minting function (the rest of the code is uploaded and verified on etherscan):

function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) {
    totalSupply = SafeMath.add(totalSupply, _amount);
    balances[_to] = balances[_to].add(_amount);
    emit Mint(_to, _amount);
    emit Transfer(0x0, _to, _amount);
    return true;
}
  • 1
    How do you mint? Is the minting supposed to increase your totalSupply variable? – Lauri Peltonen Jul 19 '18 at 10:13
  • Yes, it's supposed to increase the totalSupply variable. I've added the relevant code in the question, but you can find the whole contract on etherscan. – Carlo Vespa Jul 19 '18 at 20:03
0

After a bit of digging I found your problem.

You are redeclaring the variable totalSupply in your custom token code. This overrides the variable from BasicToken contract and the variable's value is set to 0.

When you call the mint function it can't modify the value of totalSupply from your custom token because it's higher in the inheritance chain so it modifies the variable in BasicToken. I guess in theory if you then looked at the value in BasicToken you'd see the right value but you are always interacting with your custome token so you always see the value which is there.

Just remove the variable declaration from your custom token contract and it works just fine.

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.