-
Patrick said Pure Function doesn't modify or read the blockchain. So what is it actually used for? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
This short guide would be helpful |
Beta Was this translation helpful? Give feedback.
-
@MrMandu7 Now understand when we use View and when we use Pure. Every smart contract has variables that we say state/storage variables, now when we read those state variables inside the function, we have to mark our function as View. Let's say you create contract AnyName {
uint256 num = 10;
function read() external view returns(uint256) {
return num;
}
} As you can see here, I read the num state variable so in that case, I have to use view, I cannot use pure here. On the other hand, if we only read data from our function, let's say a function that returns "Hello world", in that case, we are not reading any state variable so we can mark our function as pure. Hope it clears your query if not then please ask again and I will try to clear it with a more clean example. Thank you |
Beta Was this translation helpful? Give feedback.
-
here is my take on it Pure and view functions are special functions in solidity
pure and view functions both are free if the call was from outside of the blockchain |
Beta Was this translation helpful? Give feedback.
-
You can use pure functions to do computations that do not modify the state variables, such as converting a SVG to image URI |
Beta Was this translation helpful? Give feedback.
here is my take on it
Pure and view functions are special functions in solidity
pure and view functions both are free if the call was from outside of the blockchain