Apparently, my endpoint in the following code is for a Testnet (well, specifically, Polygon-Testnet), and I’m trying to execute a flash loan, but if I want to do it on a Mainnet, it needs to be a Mainnet endpoint.
But, how do I make it from a Testnet endpoint to a Mainnet endpoint? I’m sure that I need to add a Mainnet URL from here in Infura, stuff like that.
But, where is the Testnet endpoint to be found in the code? If there is no Testnet endpoint in the code, do I need to add an .env file with the appropriate credentials? If not, then what do I do?
Any help would be appreciated, here is the code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;
import “https://github.com/aave/aave-v3-core/blob/master/contracts/flashloan/base/FlashLoanSimpleReceiverBase.sol”;
import “https://github.com/aave/aave-v3-core/blob/master/contracts/interfaces/IPoolAddressesProvider.sol”;
import (there’s a third link here, specifically for IERC20.sol from Aave V3, but that is not listed due to link limits from new users like me.)
contract SimpleFlashLoan is FlashLoanSimpleReceiverBase {
address payable owner;
constructor(address _addressProvider)
FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_addressProvider))
{
}
function fn_RequestFlashLoan(address _token, uint256 _amount) public {
address receiverAddress = address(this);
address asset = _token;
uint256 amount = _amount;
bytes memory params = "";
uint16 referralCode = 0;
POOL.flashLoanSimple(
receiverAddress,
asset,
amount,
params,
referralCode
);
}
/**
This function is called after your contract has received the flash loaned amount
*/
function executeOperation(
address asset,
uint256 amount,
uint256 premium,
address initiator,
bytes calldata params
) external override returns (bool) {
//Logic goes here
uint256 totalAmount = amount + premium;
IERC20(asset).approve(address(POOL), totalAmount);
return true;
}
receive() external payable {}
}