0

Suppose I have a contract which performs an arbitrary mathematical calculation like:

contract Add2Plus2 
{
    ...
     
    function add2plus2() external view 
    {
        return 2 + 2;
    }

    ...

}

The function does not rely on any state information of the contract, and does not actually require any knowledge of what is happening on the Ethereum chain, the EVM or otherwise. It just performs a basic mathematical calculation.

I am aware that view functions do not modify stateful variables within a contract. However, they cost gas to perform.

Question:

Is there a way to define such a function that is performed client-side, without any interaction with the EVM - and hence be gasless? If so, how would such a function be defined?

1

View and Pure functions are gasless only if they do not get called from the contract internally.

The function in the question would be gasless if called externally. Pure functions do not read or modify state, where as View functions read but do not modify state.

Your Answer

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

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