Explain solidity>safe transfers

Sending ETH Safely

Now let's complete the withdraw function by actually sending ETH to the user.

Why Not transfer()?

The old way was msg.sender.transfer(amount)

But transfer() only gives 2300 gas, which can fail with smart contract wallets.



Using call() Instead:

(bool success, ) = msg.sender.call{value: amount}("");

This sends ETH with more gas and returns a boolean success status.

The empty ("") means we're not calling a function, just sending ETH.



Checking Success:

Always check if the transfer succeeded:

require(success, "Transfer failed");



The Complete Pattern:

1. Check credits > 0
2. Store amount
3. Zero the balance (prevent reentrancy)
4. Send ETH with call()
5. Require success



Complete the withdraw() function by adding the call() and require.

Complete withdraw with call()
0%
Requirements:
Uses call() to send ETH
Calls msg.sender.call
Includes {value: amount}
Includes empty string ("")
Captures success boolean
Requires success
Require comes after call