'FLashLoan aave v3

I'm trying to make a flash loan using Aave V3. On the interface, there's a function called flashLoanSimple(), shown here:

function flashLoanSimple(
    address receiverAddress,
    address asset,
    uint256 amount,
    bytes calldata params,
    uint16 referralCode
) external;

The console returns an error:

ValueError: Gas estimation failed: 'The execution failed due to an exception.'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

I don't know which is the trouble, because I deposit Dai on the contract address, then try to make the flashLoan and failure.

Here's the full code:

contract Flasher is FlashLoanSimpleReceiverBase, Withdrawable {
constructor(IPoolAddressesProvider _providerAddress)
    FlashLoanSimpleReceiverBase(_providerAddress)
{}

function flashLoanSimple(address asset, uint256 amount) external {
    require(asset != address(0), "Address zero no");
    require(amount > 0, "Pone plata");
    address receiverAddress = address(this);
    uint256 _amount = amount * 10**18;
    bytes memory params = "";
    uint16 referralCode = 0;

    POOL.flashLoanSimple(
        receiverAddress,
        asset,
        _amount,
        params,
        referralCode
    );
}

function executeOperation(
    address asset,
    uint256 amount,
    uint256 premium,
    address initiator,
    bytes calldata params
) external override returns (bool) {
    //logic.....

    //cALCULAR PRIMA
    uint256 fee = LowGasSafeMath.add(amount, premium);
    IERC20(asset).approve(address(POOL), fee);
    return true;
}


Solution 1:[1]

You forgot to close the bracket '}' that you opened in the contract. Check if is only that what is causing that error. Too I'm seeing that you imported 'SafeMath' and not 'LowGasSafeMath'.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1