I'm testing my erc20 contract on Kovan testnet and I have an addLiquidity function that creates a token-eth pair on uniswap

function addLiquidity() external onlyOwner() {
require(!liquidityInitialized, "Liquidity already added.");
uint256 _ethBalance = address(this).balance;
_allowances[address(this)][address(router)] = type(uint256).max;
WETH = router.WETH();
pair = IDEXFactory(router.factory()).createPair(WETH, address(this));
router.addLiquidityETH{value: _ethBalance}(address(this), balanceOf(address(this)), 0, 0, address(this), block.timestamp);
liquidityInitialized = true;
}

For some reasons calling addLiquidity from Remix opens a warning popup saying that gas estimation failed and if I choose to force sending the transaction it really fails.
Any idea, at a first glance, on what am I doing wrong?

Oct 24, 2021, 5:04 PM

© 2024 Draquery.com All rights reserved.