0
0
Blockchain / Solidityprogramming~5 mins

View and pure functions in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a view function in blockchain smart contracts?
A view function is a type of function that reads data from the blockchain but does not modify the state. It does not cost gas to call because it does not change anything.
Click to reveal answer
beginner
What does a pure function mean in blockchain smart contracts?
A pure function neither reads nor modifies the blockchain state. It only uses its input parameters to compute and return a result, without any side effects.
Click to reveal answer
intermediate
Why do view and pure functions not cost gas when called externally?
Because they do not change the blockchain state, the network does not need to record any changes, so calling them is free and does not consume gas.
Click to reveal answer
beginner
Can a view function modify the blockchain state?
No, a view function is not allowed to modify the blockchain state. It can only read data.
Click to reveal answer
intermediate
Give an example of when to use a pure function in a smart contract.
Use a pure function when you want to perform calculations or return a value based only on the input parameters, like adding two numbers, without reading or changing any stored data.
Click to reveal answer
Which of the following best describes a view function?
AOnly modifies blockchain data
BModifies blockchain data
CReads blockchain data but does not modify it
DNeither reads nor modifies blockchain data
What is true about pure functions in smart contracts?
AThey can read and modify blockchain state
BThey neither read nor modify blockchain state
CThey only read blockchain state
DThey only modify blockchain state
Why do view and pure functions not consume gas when called externally?
ABecause they do not modify the blockchain state
BBecause they modify the blockchain state
CBecause they are always free
DBecause they run on a different network
Which function type can perform calculations without accessing blockchain data?
AView function
BConstructor
CFallback function
DPure function
Can a view function call a pure function?
AYes, because pure functions do not modify state
BNo, because pure functions modify state
CNo, because view functions cannot call other functions
DYes, but only if the pure function modifies state
Explain the difference between view and pure functions in blockchain smart contracts.
Think about what each function can read or change on the blockchain.
You got /4 concepts.
    Describe why calling view or pure functions externally does not cost gas.
    Consider what causes gas fees in blockchain transactions.
    You got /4 concepts.