1

function1:

    function testFunc1(uint256 num) public pure returns(uint256){
        return unm;
    }

function2:

function testFunc1(uint256 num) public returns(uint256){
            return unm;
        }

the only difference is write pure or not,what's the basis for gas's calculations?

0

3 Answers 3

0

Pure or view functions doesn't cost any gas because it doesn't alter the state of the Blockchain and gets executed only by the provider.

Public functions gets executed by every miner even if it doesn't write anything to the Blockchain. So, public functions atleast cost the base gas.

0
0

If you can make your functions pure, you should do so because a pure function costs less gas than a non-pure function if the only difference is the pure modifier. A pure function usually applies to functions that don't read state variables and are normally functions that make some type of calculations inside them without relying on external data. This is why they cost less gas.

0

View/pure doesn’t cost gas at all because it doesn’t changes the blockchain’s state.

If you don’t mark your function as pure/view the assumption is that the state will change so it would cost gas to run your code.

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