1

I would like to assert the cost of an execution within a Solidity (5.x) function before executing it. To the best of my knowledge, this sounds like an incomputable problem, but I would like to check whether this can be done before making any assumptions.

I am aware that computing the cost can be done after the computation(s) has/have ended, but I would like to see the cost before wasting any gas. The gas price for seeing the price of a computation is acceptable, as long as it is less than a price of executing the computation.

  • 2
    If you intend to execute some transaction.send(...) from an off-chain script (e.g., via web3.js), then you can use transaction.estimateGas(...), which will give you the exact gas cost in most cases. – goodvibration Oct 1 '19 at 6:29
  • "I would like to assert the cost of an execution within a Solidity ... function". – Damir Olejar Oct 1 '19 at 10:49
  • The "within a Solidity ... function" part is not specified in your question (even though you're quoting it in the comment above as if it were). The question says "before executing it", and executing it can be done both on-chain (from Solidity) and off-chain (from a web3 script, in Javascript for example). I suggest updating the question to explicitly specify your requirements. – goodvibration Oct 1 '19 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.