Solidity

Solidity Pure Functions

Solidity Pure Functions Main Tips

  • In Solidity pure functions are functions, that are promised not to modify or read the state.
  • This feature is not enforced yet, meaning that technically, they can still do anything a normal function can.

Solidity Pure Functions

In Solidity pure functions are functions, that are promised not to modify or read the state.

In addition to modifying the state, (defined in the tutorial on view functions) they also cannot read from the state.

The list below contains conditions for a function to be considered to be “reading from the state”:

  1. State variable being read.
  2. <address>.balance or this.balance being accessed.
  3. Members of msg, txblock being accessed (except for msg.sig and msg.data).
  4. Functions that are not marked pure being called.
  5. Inline assembly containing certain opcodes being used.

Example

pragma solidity ^0.4.16;

contract cont {
    function func(uint x, uint y) pure returns (uint) {
        return x * (y + 42);
    }
}

 

Try on Remix Try live on Hosting

Read previous post:
Solidity View Functions

Solidity View Functions Main Tips In Solidity view functions are functions, that are promised not to modify the state. Getter methods...

Close