3

Good day,

ERC20 specify the following 2 functions as its most important ones:

function balanceOf(address _owner) constant returns (uint256 balance){}
function transfer(address _to, uint256 _value) returns (bool success){}

But the balanceOf function is nothing more than a fancy way to access the info stored inside a simple mapping array. Why not just set the balances mapping array to be public and be done with it?

mapping (address=>uint) public balanceOf;

I feel as if I'm missing something here. As always, your help is appreciated.

1
  • Also why is the 'unit256 balance' a constant returns ? It might change or am I getting something wrong?
    – sunwarr10r
    Commented Nov 10, 2017 at 13:22

2 Answers 2

2

The function just defines a way of accessing the mapping array and assumes that you haven't set its modifier to public.

In ether wallets they both seem to work in the same way so no real difference if you just need to see balances.

0

Because of security reasons. Having the variable private allows you to lock it down behind requirements. Such as, only the owner of a token can call the tranfer() function on that token.

(You can also set another account as an "operator" of your tokens, thereby giving that "operator" account permission to call the transfer() function on your tokens).

Your Answer

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

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