0

in. https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md

it is written:

function balanceOf(address _owner) constant returns (uint256 balance)

I understand the usage of the constant modifier in decimals() and name() - but I am having trouble understanding why balanceOf() is constant

2 Answers 2

2

constant in Solidity is not the same as constant keyword in other languages.

In Solidity constant keyword mean:

  • constant function should not modify the state (not fully enforced yet)
  • constant state variable (ie. the one in the class and not in a method) is evaluated every time it is called

By the way, it might be important to mention that two new function modifiers were added. You can read about them more here and here.

0

It is marked with a keyword "constant" because it does not modify the state. However, contrary to the variables, marking functions with a "constant" keyword doesn't mean it could be executed without the need for the transaction. If you are curious, you can find more information here: Could we call a constant function without spending any gas inside a transaction function?

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.