Skip to content

Lesson 7 - 11:36 - Why are we adding gasCost to the endingDeployerBalance? #272

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

You must be logged in to vote

Whoever calls the transaction, pays the gas costs associated with it. In this function, we are calling the withdraw function.

Take this scenario.

deployer address has 1 ETH
FundMe contract has 1 ETH

If the deployer address calls the withdraw function and pulls the 1 ETH out of the FundMe contract, how much ETH will they have?

1 + 1 = 2 ETH... but they also paid the gas of calling the withdraw function.

So they would have 1 + 1 - (gascosts) = ~1.9(ish)

In our tests, we want to account for the gas costs to make it accurate.

So, following our example, if you take the test:

assert.equal(
                //BigNumber.add() function is better to perform math operations, makes it easier

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alwayscommit
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
2 participants