1

I am attempting to compile a flash loan contract. I am having issues with the external payable function. I've tried adding fallback or receive as the error message suggests but I still receive the same error. Is there a particular way this line of code needs to be written? All help appreciated. Thanks.

contract FlashLoanReceiverBase is IFlashLoanReceiver {
    using SafeMath for uint256;

    address constant ETHADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    ILendingPoolAddressesProvider public addressesProvider = ILendingPoolAddressesProvider(
        0x24a42fD28C976A61Df5D00D0599C34c4f90748c8
    );

    function() external payable {}

    function transferFundsBackToPoolInternal(address _reserve, uint256 _amount)
        internal
    {
        address payable core = addressesProvider.getLendingPoolCore();
        transferInternal(core, _reserve, _amount);
    }

    function transferInternal(
        address payable _destination,
        address _reserve,
        uint256 _amount
    ) internal {
        if (_reserve == ETHADDRESS) {
            //solium-disable-next-line
            _destination.call.value(_amount)("");
            return;
        }

        IERC20(_reserve).transfer(_destination, _amount);
    }

    function getBalanceInternal(address _target, address _reserve)
        internal
        view
        returns (uint256)
    {
        if (_reserve == ETHADDRESS) {
            return _target.balance;
        }

        return IERC20(_reserve).balanceOf(_target);
    }
}
5
  • What is the error? Where is the payable function you are referring to, it's not in the code you shared? Sep 10, 2020 at 18:10
  • Please just edit your question to include all the relevant information, in a formatted way Sep 10, 2020 at 18:20
  • All done. Thanks
    – user63620
    Sep 10, 2020 at 18:21
  • Um, what exactly are you trying to accomplish? Why do you have a line function() external payable {}? Do you simply want to be able to receive Ethers in the contract? Sep 10, 2020 at 18:23
  • It's part of a lengthy arbitrage contract. I've tried a couple of different contracts and i always get a parse error telling me to use fallback function.
    – user63620
    Sep 10, 2020 at 18:25

1 Answer 1

1

If you're on Solidity 0.6.0 or above, instead of using

 function() external payable {}

You should use new keyword receive

receive() external payable { }

Used as a fallback function after receiving ether

1
  • Thanks very much :) I will try that, much appreciated :-)
    – user63620
    Oct 28, 2020 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy