1

I have the following code snippet in my contract, trying to call flashLoan from Aave.

address private constant LINK = 0x...;

   function myFlashLoanCall(uint256 _amount, bytes memory _params) public {
        address receiverAddress = address(this);
        address onBehalfOf = address(this);
        uint256[] memory amount = [_amount];
        uint256[] memory mode;

        LENDING_POOL.flashLoan(
            receiverAddress,
            [LINK],
            amount,
            mode,
            onBehalfOf,
            _params,
            0
        );
    }

When I try to compile I get the following two errors:

TypeError: Type uint256[1] memory is not implicitly convertible to expected type uint256[] memory.
        uint256[] memory amount = [_amount];
        ^---------------------------------^

and

 TypeError: Invalid type for argument in function call. Invalid implicit conversion from address[1] memory to address[] memory requested.
            [LINK],
            ^----^

What am I doing wrong for each error. How should my code be structured instead?

2
  • why are you declaring array of amounts ? are you going to call multiple flashloans? just single uint256 amount variable is enough. remove this line uint256[] memory amount and pass amount directly to flashLoan() , add memory keyword to the parameter amount in function's signature. The amount is what you want to borrow
    – Nulik
    Jul 17 at 19:51
  • The flashloan from aave takes arrays as params. If I try what you suggest I get: TypeError: Invalid type for argument in function call. Invalid implicit conversion from address to address[] memory requested. LINK, Jul 18 at 0:13

Your Answer

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

Browse other questions tagged or ask your own question.