1

Say I am expecting a result to be returned. What will happen to the return value when the call will go through to the fallback since the fallback does not return anything?

uint a = otherContract.bar();

where I expect bar to return uint but otherContract does not actually implement it

function bar () returns (uint);

Will a take a value? will the cal throw?

1 Answer 1

0

The call will revert. In the below code, I created two contracts A and B, one of which has no functions, and another has empty fallback. I have written within the code the sequence of deployment and calls to check in Remix.

// SPDX-License-Identifier: Unlicensed
pragma solidity ^0.8.0;

interface IA {
    function checkBool() external returns(bool);
    function checkUint() external returns(uint256);
}

// 1. Deploy A
contract A {
}

interface IB {
    function checkBool() external returns(bool);
    function checkUint() external returns(uint256);
}

// 2. Deploy B
contract B {
    fallback() external {
    }
}

// 3. Deploy C
contract C {
    event BoolEvent(bool);
    event UintEvent(uint256);

    // 4. Call this function with Deployed A
    function checkBoolA(address _A) public {
        emit BoolEvent(IA(_A).checkBool());
    }

    // 5. Call this function with Deployed B
    function checkBoolB(address _B) public {
        emit BoolEvent(IB(_B).checkBool());
    }

    // 6. Call this function with Deployed A
    function checkUintA(address _A) public {
        emit UintEvent(IA(_A).checkUint());
    }

    // 7. Call this function with Deployed B
    function checkUintB(address _B) public {
        emit UintEvent(IB(_B).checkUint());
    }
}

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.