I would like to write an external view function that throws when being executed on-chain, but does not throw when executing client-side. (for example when it is called through web3.js)

Is there a way to do this?

  • 2
    I very much doubt there's a way to do this. (If there is, it's likely to be considered a bug and fixed in the future.) I'm curious why you would want this.
    – user19510
    Commented Jul 9, 2018 at 19:20

1 Answer 1


Edit 2021: Since solidity 0.5.0, the built-in function gasleft() replaced msg.gas.

∀ transactions: msg.gas > 0

Check for the gas amount !

  • msg.gas was deprecated in solidity version 0.4.22, and it no longer compiles since version 0.5.0
    – Jesbus
    Commented Dec 20, 2021 at 0:28

Your Answer

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

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