Add Liquidity to PancakeSwap with Solidity (Urgent - 24h or less)
Budget: €8 – €30 EUR
I need to call addLiquidityETH function in order to create a liquidity pool in PancakeSwap and add BNBs/myTokens balance to the pool.
Actually I have the following code:
- Inside constructor I initialise this variables:
uniswapV2Router02 = IUniswapV2Router02(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet address
uniswapV2Factory = IUniswapV2Factory(uniswapV2Router02.factory());
uniswapV2Pair = IUniswapV2Pair(uniswapV2Factory.createPair(address(this), uniswapV2Router02.WETH()));
- And I have this function:
function addLiquidityToPS(uint256 amountToken) external payable onlyOwner {
require(msg.value > 0, "Add more BNB liquidity");
require(amountToken > 0, "Add more Token liquidity");
approve(address(uniswapV2Router02), amountToken);
uniswapV2Router02.addLiquidityETH{value: msg.value}(
address(this),
amountToken,
0,
0,
owner(),
block.timestamp
);
}
But when I call this function I get this error, either on testnet or mainnet:
{ "code": 3, "message": "execution reverted: TransferHelper: TRANSFER_FROM_FAILED", "data": "0x08c379a0000.....}
I have tokens and BNBs both in the address of the owner and in that of the contract, I don't think it's an allowance problem either, since I approve by hand and it continues to give an error.
Actually I have the following code:
- Inside constructor I initialise this variables:
uniswapV2Router02 = IUniswapV2Router02(0xD99D1c33F9fC3444f8101754aBC46c52416550D1); //Testnet address
uniswapV2Factory = IUniswapV2Factory(uniswapV2Router02.factory());
uniswapV2Pair = IUniswapV2Pair(uniswapV2Factory.createPair(address(this), uniswapV2Router02.WETH()));
- And I have this function:
function addLiquidityToPS(uint256 amountToken) external payable onlyOwner {
require(msg.value > 0, "Add more BNB liquidity");
require(amountToken > 0, "Add more Token liquidity");
approve(address(uniswapV2Router02), amountToken);
uniswapV2Router02.addLiquidityETH{value: msg.value}(
address(this),
amountToken,
0,
0,
owner(),
block.timestamp
);
}
But when I call this function I get this error, either on testnet or mainnet:
{ "code": 3, "message": "execution reverted: TransferHelper: TRANSFER_FROM_FAILED", "data": "0x08c379a0000.....}
I have tokens and BNBs both in the address of the owner and in that of the contract, I don't think it's an allowance problem either, since I approve by hand and it continues to give an error.