When creating a simple token, this code is suggested in the Ethereum website:

contract MyToken {

    mapping (address => uint256) public balanceOf;
    function MyToken(uint256 initialSupply) {
        balanceOf[msg.sender] = initialSupply;// Give the creator all

This works as expected in the testnet (the creator receive the tokens), but if you change the name of balanceOf to, let's say, balances, the contract does not send the token to the creator (or the mist wallet does not see them).

It happen to be that balanceOf is the name of a function in the ERC20 standard interface (https://theethereum.wiki/w/index.php/ERC20_Token_Standard). However, in this code it is defined as a variable.

Any explanation? Is solidity assuming things based on the name of the variables?


The public keyword in mapping (address => uint256) public balanceOf will let the compiler create a public getter function with the same name.

  • this means balanceOf is a reserved name?, I am having problems understanding why changing the name of the variable will change the behavior of the contract.
    – Jaime
    Feb 22 '18 at 8:46
  • If ERC20, the caller is expecting a predefined set of functions (balanceOf being one of them), otherwise the implementation is not compliant with ERC20.
    – ivicaa
    Feb 27 '18 at 13:29

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .