Let's say I have a view function that accesses a storage mapping like so:

function performCalculation(uint256 _id) public view returns(uint256) {
      uint256 memory someValue = someMapping[_id];
      return someValue - 10;

And I have another function which also accesses that same value:

function someFunction(uint256 _id) external {
      uint256 storage someValue = someMapping[_id];
      // do something

If inside someFunction I needed to perform the same calculation that performCalculation does, would calling performCalculation from someFunction use more gas as it is accessing storage again? Would the better solution be to just do the same calculation inline using the someValue from someFunction?

1 Answer 1


From someFunction in a transaction, it would cost either more or the same gas.

The fact that it's a view function only allows calling this using a node RPC instead of submitting a transaction, but it doesn't reduce the cost of a mined transaction.

  • Does this apply if someFunction was called externally, which would then mean performCalculation was called internally by someFunction?
    – luxo
    May 4, 2022 at 20:17
  • I misunderstood your question, fixed my answer accordingly.
    – Kof
    May 4, 2022 at 20:46

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.