Lesson 7: Staging Test Withdraw #2912
-
Hello guys, I just want to clarify the 'payable' in the withdraw function of the FundMe contract. Why is there a payable there? Please enlighten me. Thank you! function withdraw() public payable onlyOwner {
for (
uint256 funderIndex = 0;
funderIndex < s_funders.length;
funderIndex++
) {
address funder = s_funders[funderIndex];
s_addressToAmountFunded[funder] = 0;
}
// reset the array
s_funders = new address[](0);
// actually withdraw the funds
// transfer
// msg.sender = address
// payable(msg.sender) = payable address
// payable(msg.sender).transfer(address(this).balance);
// send
// bool sendSuccess = payable(msg.sender).send(address(this).balance);
// require(sendSuccess, "Send failed");
// call
(bool callSuccess, ) = i_owner.call{value: address(this).balance}("");
require(callSuccess, "Call failed");
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@lexorrr You do not need payable with withdraw function, people also made a PR to remove it from repo code. |
Beta Was this translation helpful? Give feedback.
-
As I see Patrick doesn't use For the explanation:
|
Beta Was this translation helpful? Give feedback.
-
To this end, E.g. you would have noticed the use of |
Beta Was this translation helpful? Give feedback.
@lexorrr You do not need payable with withdraw function, people also made a PR to remove it from repo code.