Lesson 7: More optimized withdraw #4006
carledwardfp
started this conversation in
Show and tell
Replies: 1 comment
-
This can further be optimized to function withdraw() public onlyOwner {
uint256 fundersLength = s_funders.length;
for (uint256 i = 0; i < fundersLength; ) {
address funder = s_funders[i];
s_funderToAmountFunded[funder] = 0;
unchecked {
i++;
}
}
s_funders = new address[](0);
(bool success, ) = payable(i_owner).call{value: address(this).balance}("");
if (!success) revert FundMe__CallFailed();
}
since we are sure that we wont overflow or underflow [reference] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I tried a different gas optimization for the
withdraw
function containing for loop:And it generated a better result as seen in
gas-report.txt
:As compared to:
Compiler used:
0.8.17
Beta Was this translation helpful? Give feedback.
All reactions