1

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

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.

1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.