Skip to content

How does the view function getPrice consume no gas? #57

Answered by alwayscommit
gmluqa asked this question in Q&A
Discussion options

You must be logged in to vote

Summary

If you don't modify the state of the blockchain, it won't cost any gas. Reading from the blockchain (even reading with some math) is really easy for nodes to do.

I think this post explains it well.
https://ethereum.stackexchange.com/questions/52885/view-pure-gas-usage-cost-gas-if-called-internally-by-another-function/52887#52887

Additional information

Gas is applied when you modify the state of the smart contract, thereby modifying the entire blockchain. If you're simply reading from off-chain and doing some math on it, that won't cost any gas. Only if you modify the state of the contract, it'll cost gas.

To add to this, if pure/view functions are called externally (which is the c…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@gmluqa
Comment options

Comment options

You must be logged in to vote
2 replies
@gmluqa
Comment options

@gmluqa
Comment options

Answer selected by PatrickAlphaC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants