If I use msg.gas statement inside my contract, does executing that line itself need gas? If yes, how much does it need?
2 Answers
Please note that msg.gas is deprecated. You should use gasleft() if you are over version 0.4.21.
The function itself uses the gas opcode which is in the base group and thus costs 2 gas.
msg.gas was renamed to gasleft().
Anyway, everything has a cost, for gasleft() it is defined here. The associated cost is GasQuickStep which is set to 2.
It therefore cost you 2 gas to know how much gas is left.