I create this contract using Remix.

When I call to totalsupply,it shows 0.

What am I doing wrong? Any help is much appreciated.

enter image description here

enter image description here

  • Check if your contract is deployed properly. You can also try to debug your tx. – Prashant Prabhakar Singh Jun 29 '18 at 4:15
  • Please copy and paste your code, rather than a screen shot. Having the actual code makes your question show up in the search results more easily - a screenshot will impede that search. – Greenonline Jun 29 '18 at 10:09

You have naming conflict here:

function totalSupply () public constant returns (uint totalSupply) {
    return totalSupply;

Statement return totalSupply refers to returns (uint totalSupply) rather than to totalSupply state variable.

BTW, simplest fix would be to remove this function completely, as totalSupply state variable is already declared as public, so no need to define explicit getter.

| improve this answer | |

If you are using the compiler version greater than 0.4.18 than replace the constant with view.

| improve this answer | |
  • 1
    Please could you expand upon your answer, as it is rather short and, as it stands, would serve better as a comment? Maybe provide an example of the corrected code? See How do I write a good answer? – Greenonline Jun 29 '18 at 10:12

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.