Focus mode

Smart Contract Development with Solidity

View and Pure Functions

Code from video: https://solidity-by-example.org/view-and-pure-functions/ 

View: Indicates that the function will read data from the blockchain but not modify it. 

View functions ensure that state variables are not changed. If the following statements are present in the function, it is considered to be changing state, and the compiler issues a warning.

  • Changing state variables
  • Emitting events
  • Creating other contracts
  • Using selfdestruct
  • Sending Ether via calls
  • Calling any function which is not marked view or pure
  • Using low-level calls
  • Using inline assembly containing certain opcodes

Pure: It states that the function will neither read nor modify data from the blockchain.

Pure functions ensure that data is not read and not modified. If the following statements are present in the function, it is considered to be changing state, and the compiler issues a warning.

  • Reading state variables
  • Accessing address(this).balance or <address>.balance
  • Accessing any of the special variable of block, tx, msg
  • Calling a function which is not pure
  • Etc are present in pure functions

Resources: 

You can find detailed further information from Solidity Official documentation (in English): 

https://docs.soliditylang.org/en/v0.8.15/types.html#function-types 

https://www.tutorialspoint.com/solidity/solidity_view_functions.htm 

https://www.geeksforgeeks.org/solidity-view-and-pure-functions/

https://github.com/itublockchain/web3-bootcamp/tree/master/1x1_Functions

left-disk

Programs to Accelerate Your Progress in a Software Career

Join our 4-8 month intensive Patika+ bootcamps, start with the fundamentals and gain comprehensive knowledge to kickstart your software career!

right-cube

Test

Comments

You need to enroll in the course to be able to comment!