I've read in the documentation that reading data from the blockchain does not cost gas. It costs gas only when saving data to the blockchain or when executing operations like +, -, * etc (see the opcodes).
BUT, I've created this simple contract:
pragma solidity ^0.5.0;
contract A{
uint public x = 10;
function get_x() public view returns(uint){
return x;
}
}
When calling get_x() in remix it says: execution cost: 413 gas (Cost only applies when called by a contract). What does it mean? Do I have to pay gas for calling get_x(). If yes, why?
More that that, if I get the value of x whitout calling the get_x() getter function (it's a public variable so a getter with the same name x() is automatically created) I get another gas value: execution cost: 383 gas (Cost only applies when called by a contract)