function Initialize () external onlyOwner {
        require(!tradingOpen,"init already called");
        uint256 tokenAmount = balanceOf(address(this)).sub(_totalSupply.mul(_initialBuyTax).div(100));
        uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        _approve(address(this), address(uniswapV2Router), _totalSupply);
        uniswapV2Pair = IUniswapV2Factory(
        uniswapV2Router.addLiquidityETH{value: address(this).balance} (
        IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max); 

What does this function do and when are you supposed to call it?

1 Answer 1


This function initialises a contract by setting up a Uniswap liquidity pool.

Here’s the breakdown of what it does:

  • Checks if the contract initialisation hasn’t been called yet.

  • Calculates the amount of tokens available for liquidity.

  • Sets up the Uniswap router and pair.

  • Adds liquidity to the Uniswap pool using ETH.

  • Approves the Uniswap router to spend tokens.

Basically, this function is meant to be called once during the contract deployment phase to set up liquidity on Uniswap.

  • Thank you, when you say set up liquidity, does it mean that this function will create initial liquidity pool of pair tokens/ETH automatically and programmatically on Uniswap? Apr 11 at 3:36
  • Yes, the function sets up the initial liquidity pool for the token on Uniswap by adding an equivalent amount of ETH to create a pair, enabling trading against ETH. Apr 11 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.