Solidity:Pure And View Functions
March 11th, 2023

Functions can be declared as view if it is not modifying blockchains state. In our context, blockchain state is the value of the number variable.

setNumber method changes the value of the variable so it cannot be declared as view. But GetNumber only reads blockchain’s state so it should be declared as view.

Pure methods are the ones that don’t read or modify the blockchain’s state.addTwoNumbers answers the description of pure methods.

Subscribe to Yusuf.dev
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Yusuf.dev

Skeleton

Skeleton

Skeleton