Skip to content

Lesson 4. Added a + on the mapping implementation on the fund() function #1987

Answered by alymurtazamemon
davidinci7 asked this question in Q&A
Discussion options

You must be logged in to vote

@davidinci7 Above @krakxn well explained the mathematics behind adding +. I just want to add the purpose of using += instead of =.

We want everyone to fund our contract along with it we want to trace that which address gives how much amount.

So if we use;

addressToAmountFunded[msg.sender] = msg.value; 

Every time an address fund the contract its latest amount will be saved in the mapping. Ex. if the first time an address funds 1 ETH and the next time it funds 2 ETH. The mapping will tell us that the address has only funded 2 ETH because that was the last funded amount but that is not true because the same address has funded a total of 3 ETH. That's what we are doing by using the + operator.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@krakxn
Comment options

@davidinci7
Comment options

@krakxn
Comment options

Answer selected by davidinci7
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