Lesson-9: Need a code explanation #1891
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
So in this line of code (bool success, ) = recentWinner.call{value: address(this).balance}(""); In this line uint256 totalContractBalance=address(this).balance;
(bool success, ) = recentWinner.call{value: totalContractBalance}(""); here Edit: Changed return to store. |
Beta Was this translation helpful? Give feedback.
-
The above answer is partially wrong, and as so I will dissect—for concision—it in parts.
|
Beta Was this translation helpful? Give feedback.
The above answer is partially wrong, and as so I will dissect—for concision—it in parts.
(bool success, )
stores the value of either true or false, depending on what the right-hand side to the=
operator evaluates to.recentWinner.call
this results in thecall
keyword being used. Put simply, think of it as a "transferring money" keyword. So, we aretransferring money
torecentWinner
's address, not "some address".call{value: totalContractBalance}
call takes in avalue
, which specifies the above quantity of the "money"("")
this is just a message, as to which we do not assign any, i.e an empty string. Hence, no message. BTW, this is used in advanced demonstrations usually.