If I make a call to an external smart contract that uses a function (transfer) which of the following is safer.
- using abi.encodeWithSignature
(bool success, ) = address(contractInstance).call(abi.encodeWithSignature("transfer(address, uint256)", msg.sender, amount));
require(success, "Failed to send tokens");
- direct call
contractInstance.transfer(msg.sender, amount)
for both im using reentrancy guard.
Thanks!
balanceBefore + amountTransferred
, everything else is unsafe. A token can report transfer as successful via event but don't really transfer anything. you have to addbalanceOf()
call (and spend more gas). Check out , for example, theflash()
function of UniswapV3Pool contract, this is 100% safe