I came across many blogs saying the defacto standard to send ether from one contract to another and why one is better than the other. However, what is the best practice for sending ether from contract to EAO (out of three withdrawal functions)?
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
contract WalletApp {
mapping(address => uint256) public balances;
function depositBalance() external payable {
balances[msg.sender] = msg.value;
}
// Different ways to withdraw the deposit to externally owned account!
// Gas usage: 30462 gas
function withdrawDeposit() external payable {
(bool success, ) = payable(msg.sender).call{
value: balances[msg.sender]
}("");
require(success);
}
// Gas usage: 30320 gas
function withdrawDeposit2() external payable {
payable(msg.sender).transfer(balances[msg.sender]);
}
// Gas usage: 30256 gas
function withdrawDeposit3() external payable {
(bool success) = payable(msg.sender).send(balances[msg.sender]);
require(success);
}
}