1

I was wondering if interface functions automatically revert the whole transaction on failure or not?

Let's say I want to call the sync() function of a liquidityPair, which usually returns no boolean:

function sync() external;

If I want to check for success of that function, I could use a low level call like this:

function syncOne() external {
    (bool success, ) = liqPair.call(abi.encodeWithSignature("sync()"));
    require(success);
}

However, let's say I want to use it as part of an interface:

interface ILiqPair {
    function sync() external;
}

...


function syncTwo() external {
    ILiqPair(liqPair).sync();
}

Would this interface call already revert the transaction if the sync() call fails? Or would I need to edit the interface to return a boolean, even tho officially it doesn't return any bool value, and check for it like this?

interface ILiqPair {
    function sync() external returns (bool);
}

...


function syncThree() external {
    (bool success) = ILiqPair(liqPair).sync();
    require(success);
}

Also I would like to know in general, when you should check for an external call to succeed?

Like, obviously if you do a low level call ETH transfer... but other than that, should you even ever check for functions like the one above if they succeeded or not? Or in other words, can they even actually fail?

1 Answer 1

0

Interfaces don't really give a contract any extra functionality. So if a function doesn't return a boolean, using it through an interface doesn't magically add a return value to it.

The only way to get a success boolean is to use the kind of low-level calls, as you are doing.

Whether you should check for a revert or not depends on your needs. The typical scenario is that everything reverts if anything reverts in the call chain. You can catch reverts in calls to external contracts with try/catch structure, if needed. But if you don't use try/catch nor low level calls, a revert in the called contract will revert the whole transaction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.