[Ethereum] accessing global variables cost gas

solidity

I assume reading global variables don't cost gas since it's not part of the contract, but I wanted to make sure in the future in case I have to optimize contracts for gas usage.

Best Answer

Those are not functions but they are globally available variables (http://solidity.readthedocs.io/en/v0.4.24/units-and-global-variables.html).

As pointed out by @Ismael in the comments, calling them does cost gas when used in a transaction. Inside a (local) call they are free (but rather pointless - what would be the point of checking msg.sender locally?).

Related Topic