0

I am trying to add liquidity on pcs testnet. Here is the code snippet:

 
        function _addLiquidity() payable public {
         
         
           uint256 _amountToken = balanceOf(address(this));
            uint256 _amountETH = msg.value;
            uint256 _liquidity = _amountETH/_amountToken;
            
            _approve(address(this),address(_router),balanceOf(address(this)));
             IERC20(pancakeswapV2Pair).approve(address(_router), type(uint).max);
            
          (amountToken, amountETH, liquidity) =_router.addLiquidityETH(pancakeswapV2Pair, _liquidity, _liquidity*99/100, _amountETH*99/100, owner(), block.timestamp+60);
          
  
            
            emit CreatedLiquidity (amountToken, amountETH, liquidity);
            
        }

when I deploy contract on bsc testnet and try to add liquidity there is an error. Here is contract address on bsc testnet: 0x65610bfccbda12d1604294788dd63ef3d47338c3

Any help would be appreciated. Thanks.

UPDATE 1

I tried updating code according to the open-source codebase of simillar contracts. My new code looks like this:

  function _addLiquidity() payable public {
         
         
           uint256 _amountToken = balanceOf(address(this));
            uint256 _amountETH = msg.value;
           
            
            _approve(address(this),address(_router),balanceOf(address(this)));
          
            
          (amountToken, amountETH, liquidity) =_router.addLiquidityETH{
              value: _amountETH
              
          }
              (
                  pancakeswapV2Pair,     
                  _amountToken,  
                  0, 
                  0,
                  owner(),              
                  block.timestamp+60
                  );
          
  
            
            emit CreatedLiquidity (amountToken, amountETH, liquidity);
            
        }

Unfortunately still problem when trying to execute liquidity function. The new contract address on bsc testnet: 0x6220eC7F45d0533549dD4300Dd3F18231eEcAc55

Anyone willing to explain what is the problem in the code ? Thanks in advance.

1
  • Do you have a failed transaction hash?
    – Ismael
    Aug 28 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.