Solidity Gas Consumption – Analyzing Gas Consumption of Calling a View Function from Another Function

gassolidity

I have a public view function that have a for loop inside of it, I put the loop inside the view function so I wont need to worry about the gas.

now my question is if I call the function internally from an other function that is not a view function will that create the possibility of high gas consumption (because of the for loop) ?

Best Answer

Even if you make a function a view function, you still have to pay full gas costs if it's being called inside a transaction. Such view functions are only free if called locally, not inside a transaction.

So, yes, you will have to pay for full processing of the function if called from a non-view function (inside a transaction).

Related Topic