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 2


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.