Given that this is a sample balanceOf function code:
function balanceOf(address tokenOwner) public view returns (uint balance) {
return balances[tokenOwner];
}
and this function is view
function, does it's execution cost gas? If I understand correctly, balances array has to be read with SLOAD
, and this is not gas free. balances is mapping(address => uint256)
variable.
So how come that sites like etherscan.io provide interface to query balance of erc-20 tokens for free? E.g. this old EOS token contract, where I can run balanceOf on any address and get response instantly free of charge.
Thanks for explaining!