Fail with error '27' - Aave flashloans solidity

I have succesfully deployed the contract to the goerli testnet, via hardhat. However when I try to call the requestFlashLoan function with metamask, the transaction suggested gas fee seems unusually large and fails with the error “Fail with error ‘27’”. I have found this to mean ‘The caller of the function is not the lending pool configurator’. However I am still stuck on how to actually fix this.

Been stuck on this for a couple of days now, any direction would be much appreciated!

Tx : Goerli Transaction Hash (Txhash) Details | Etherscan

My solidity code is below.

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10; // .10 because thats the version a lot of the aave contracts that will be used are on.

import {FlashLoanSimpleReceiverBase} from "@aave/core-v3/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol";
import {IPoolAddressesProvider} from "@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol";
import {IERC20} from "@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol";

contract FlashLoan is FlashLoanSimpleReceiverBase {
    address payable owner;

    constructor(address _addressProvider)
        FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider))
    {
        owner = payable(msg.sender);
    }

    function executeOperation(
        address asset,
        uint256 amount,
        uint256 premium,
        address initiator,
        bytes calldata params
    ) external override returns (bool) {
        // we have the borrowed funds
        // Logic
        uint256 amountOwed = amount + premium;
        IERC20(asset).approve(address(POOL), amountOwed);

        return true;
    }

    function requestFlashLoan(address _token, uint256 _amount) public {
        address recieverAddress = address(this);
        address asset = _token;
        uint256 amount = _amount;
        bytes memory params = "";
        uint16 referralCode = 0;

        POOL.flashLoanSimple(recieverAddress, asset, amount, params, referralCode);
    }

    function getBalance(address _tokenAddress) external view returns (uint256) {
        return IERC20(_tokenAddress).balanceOf(address(this));
    }

    function withdraw(address _tokenAddress) external onlyOwner {
        IERC20 token = IERC20(_tokenAddress);
        token.transfer(msg.sender, token.balanceOf(address(this)));
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the contract owner can call this function");
        _;
    }

    receive() external payable {}
}
1 Like

Hello guy, i think you try to borrow to a wrong address token pool.<

The function requestFlashLoan(_token, _amount)
takes 2 parameters : address of token you want to borrow and amount

I think you pass a wrong address of token to first parameter.

Try to use this official address of USDC Pool on AAVE V3 Testnet :
0xa2025b15a1757311bfd68cb14eaefcc237af5b43

(see this address on documentation : V3 Testnet Addresses - Developers)

All addresses of tokens you can borrow on a flashloan is on this documentation

1 Like

Ah, yes that did it! Indeed I had used the wrong USDC contract address! Very much appreciated! :smiley: