Hello Super Shadowy Devs
Hi, I am trying to push a Transaction for my newly created contract SwapAtUniswap (deployed on Kovan) but it fails due to the following reasons
**Please also have a look at my code **
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.6;
import '@uniswap/v2-periphery/contracts/UniswapV2Router02.sol';
import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
//import "@openzeppelin/contracts/access/Ownable.sol";
contract SwapAtUniswap {
UniswapV2Router02 internal router;
AggregatorV3Interface internal ethUsdPriceFeed;
AggregatorV3Interface internal linkUsdPriceFeed;
address [] public wethLinkKovanPath;// = ["0xd0A1E359811322d97991E03f863a0C30C2cF029C", "0xa36085F69e2889c224210F603D836748e7dC0088"];
uint256 constant denom = 1000;
uint256 deadline;
constructor(address payable _router, address _ethUsdPriceFeed, address _linkUsdPriceFeed) public {
router = UniswapV2Router02 (_router);
ethUsdPriceFeed = AggregatorV3Interface(_ethUsdPriceFeed);
linkUsdPriceFeed = AggregatorV3Interface(_linkUsdPriceFeed);
}
function swapETHForLink(uint _amountOut, address[] memory _wethLinkKovanPath, address to, uint _deadline) public {
uint256 ethUsdPrice = getLatestEthUsdPrice();// will return 8 decimals
uint256 linkUsdPrice = getLatestLinkUsdPrice(); // will return 8 decimals
deadline = _deadline;
wethLinkKovanPath = _wethLinkKovanPath;
uint256 i;
for (i = 0; i < 1; i ++) {
if ( (linkUsdPrice/ethUsdPrice) <= 9/denom ) {
router.swapETHForExactTokens(_amountOut, wethLinkKovanPath, to , deadline);
}
}
}
function getLatestEthUsdPrice() public view returns(uint256) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = ethUsdPriceFeed.latestRoundData();
return uint256(price);
}
function getLatestLinkUsdPrice() public view returns(uint256) {
(
uint80 roundID,
int price,
uint startedAt,
uint timeStamp,
uint80 answeredInRound
) = linkUsdPriceFeed.latestRoundData();
return uint256(price);
}
}
Environment - Remix
**
Please help check my Code too (as I am new to solidity) if i am going wrong anywhere because I am just creating a simple Transaction of swapping ETH for Link whenever the price of Link < 0.009 ETH....... But as you see "Gas estimation failed Warning" is showing on Remix and even if i force send the Transaction I get a Revert Error by UniswapV2Router02 of Gas Estimation costs ??
So how to solve this ??
Meanwhile, also see my Kovan.etherscan.io snapshot regarding my Contract Creation, it says that Gas Limit:
530,913
Gas Used by Transaction:
530,913 (100%)
Maybe because the contract creation has used all gas?, and hence now i cannot send any transactions forward or if not, then what does this really mean ? I am unable to solve this , so kindly help
I am also getting a compilation warning as follows: Unable to understand what it means:
Thanks & regards
Suveett Kalra
**