4

I'm writing a very basic ERC20 token using solidity in the Mist wallet. For some reason the compiler doesn't like the totalSupply() function name. If I change this name it compiles fine.

To be ERC20 compliant, this function has to be signed this way.

How do I get around this error?

Solidity Code

enter image description here

2 Answers 2

3

I think your function return argument should be renamed - this is what the compiler is really complaining about:

function totalSupply() constant returns (uint256 something) {

It's actually optional to name the return argument here; you can just put its type:

function totalSupply() constant returns (uint) {

[For future reference, it would be easier to check if could post the code itself rather than an image of the code so we can cut and paste into the compiler.]

2

Option 1

A typical fix and implementation of an ERC20 token is to rename the public variable to totalSupply (no underscore) and remove the function totalSupply as it would then be auto-generated by Solidity.

Explanation of shadowing error message

function totalSupply() constant returns (uint256 totalSupply) indicates to the compiler that the return value will be variable totalSupply (without underscore).

But the function is returning the value of another variable (looks the same but it's different since it has an underscore). So the compiler error is because the totalSupply variable is being overridden / shadowed by another variable.

Option 2

As @benjaminion explained, do not name the return value and just use:

function totalSupply() constant returns (uint256)

There is now no variable to shadow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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