0
contract ContractA {
    constructor() payable {}

    function getTransfer() public {
        uint256 transferAmount = 0.1 ether;
        (bool success, ) = msg.sender.call{value: transferAmount}("");
        require(success, "Transfer failed");
    }
}
interface IContractA {
    function getTransfer() external;
}
contract ContractB {
    IContractA public contracta;

    constructor(address contractAddress) payable {
        contracta = IContractA(contractAddress);
    }

    function getTransfer() public payable {
        contracta.getTransfer();
    }
}

When calling ContractB.getTransfer() it always fails the msg.sender.call. Is it possible to do this?

1 Answer 1

1

The issue was a lack of fallback()/receive() functions. Hope this helps someone else down the line.

Working code looks like this:

contract ContractA {
    constructor() payable {}

    function getTransfer() public {
        uint256 transferAmount = 0.1 ether;
        (bool success, ) = msg.sender.call{value: transferAmount}("");
        require(success, "Transfer failed");
    }
}

interface IContractA {
    function getTransfer() external;
}

contract ContractB {
    IContractA public contracta;

    constructor(address contractAddress) payable {
        contracta = IContractA(contractAddress);
    }

    function getTransfer() public payable {
        contracta.getTransfer();
    }

    fallback() external payable {}

    receive() external payable {}
}

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.