Nice solution @Adrian1
You have added all of the additional lines of code needed to solve the problem with the withdraw function.
Now have a look at this post which explains an important security modification that should be made to the order of the statements within your withdraw function body.
Some additional comments âŚ
(1)
No ⌠this line of code doesnât add Ether to the contract address balance.
A function is marked payable
when it needs to receive Ether from an external address to add to the contract address balance . Including payable
in a function header enables the Ether value sent to the function to be added to the contract address balance, without us having to add any further code for this. In the deposit() function, this happens automatically because we have marked the function as payable
. The line âŚ
⌠then adds the same value to the individual userâs balance in the mapping, in order to keep track of their share of the total funds held in the contract.
(2)
To clarify âŚ
The _transfer() helper function is called with 3 arguments. These 3 values are input into the _transfer() function and assigned to 3 corresponding parameters:
The argument msg.sender
(an address) is assigned to the from
parameter.
The argument recipient
(an address) is assigned to the to
parameter.
The argument amount
(an unsigned integer) is assigned to the _amount
parameter.
msg.sender
always references the address that has called the function in which it is used.
(3)âYou now have the emit statement for the DepositDone event in the correct position in the deposit function
(4)âHave a look at the names of all of your functions, and think about what I said in my feedback for your Events Assignment code regarding the importance of consistency with names âŚ
Let me know if anything is unclear, or if you have any questions