Openzeppelin safeERC20 doesn't return bool

I want to achieve the following:

using SafeERC20 for IERC20;

require(IERC20(_token).safeTransfer(_to, _value), ERROR_TOKEN_TRANSFER_REVERTED);

both SafeERC20 and IERC20 are from openzeppelin. ^0.8.0 versions.

The above code fails and doen't get compiled.

No matching declaration found after argument-dependent lookup.

I looked into it and realize that none of the safe functions return any booleans. So how can I achieve what I want ? I need to have my own require which will have my own error message.

Any ideas ?

Hello @novaknole

IERC20(_token).safeTransfer(_to, _value)

does not return anything if the transfer succeeds. If the transfer fails, it will revert with one of the following messages:

  • Address: call to non-contract: the address provided is not a contract
  • SafeERC20: low-level call failed: the transfer call reverted
  • SafeERC20: ERC20 operation did not succeed: the transfer returned false.

TLDR: You don't need to use require to check it, its already safe.


If you want your own error message, SafeERC20 will not be useful to you. But using IERC20 directly and checking the boolean will not help you either, because most ERC20 implementations will revert and Solidity will bubble the revert, so you would need to use try catch.