Skip to content

Lesson 2, Calling a view function inside of a gas-calling function #541

Answered by 0xSanyam
nkt2pd asked this question in Q&A
Discussion options

You must be logged in to vote

@Quent-eth view or pure function when called alone don't spend gas, however if a gas calling function calls them, then it will cost gas, like in this tutorial, I called the retrieve() function inside the store() function

function retrieve() public view returns(uint256) {
        return favoriteNumber;
    }
function store(uint256 _favoriteNumber) public virtual {   
        favoriteNumber = _favoriteNumber;
        retrieve();
    }

There comes a difference of gas costs depending whether the store function is called with or without the retrieve() function.

In my case the transaction cost was 43,746 without calling the view function and 43,886 with calling the view function.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

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

Answer selected by PatrickAlphaC
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants