I need a help, I've been trying to fix a problem in my code for 2 days.
In the testnet everything works, but when I go to deply on the bsc mainnet and call the buyToken method I always get the Pancake K error.
Dec 31, 2021, 5:04 PM
This is my code:
function buyToken(
address _tokenToBuy,
uint256 bid,
uint256 slippage
) public onlyOwner {
IPancakePair pair = IPancakePair(
PancakeLibrary.pairFor(factory, WETH, _tokenToBuy)
);
TransferHelper.safeTransfer(WETH, address(pair), bid);
address[] memory path = new address[](2);
path[0] = WETH;
path[1] = _tokenToBuy;
uint256[] memory amountsOut = getAmountsOut(
bid - ((bid * slippage) / 1000),
path
);
pair.swap(amountsOut[1], 0, address(this), new bytes(0));
}
address _tokenToBuy,
uint256 bid,
uint256 slippage
) public onlyOwner {
IPancakePair pair = IPancakePair(
PancakeLibrary.pairFor(factory, WETH, _tokenToBuy)
);
TransferHelper.safeTransfer(WETH, address(pair), bid);
address[] memory path = new address[](2);
path[0] = WETH;
path[1] = _tokenToBuy;
uint256[] memory amountsOut = getAmountsOut(
bid - ((bid * slippage) / 1000),
path
);
pair.swap(amountsOut[1], 0, address(this), new bytes(0));
}
Dec 31, 2021, 5:05 PM
Have you changed the pancake router address for the mainnet?
No
If you don't care how much you get back then set it to 0 and it will return whatever the current conversion is.
I have implemented an autoliquidity in my token but its taking about 400k gas to both swap the tokens for BNB and add the liquidity back to the pool. This is making my transaction costs too high for my desired use. Is 400k gas for these operations correct?
Dec 31, 2021, 6:26 PM
You could just fork the network, use hardhat console.log and gasleft to check wich parts of your/their code is spending so much gas
but answering your question. Remix is good for quick things. For anything else is better to have your own dev env
Dec 31, 2021, 6:37 PM
Yeah actually thats my problem, I have used it for learning but now I try to make some real project and I think I should going with other env
Dec 31, 2021, 6:42 PM
Keep trying. I haven't configured vscode for solidity but it shouldnt take too long. Try this https://www.youtube.com/watch?v=yIfq1mT2saM
Dec 31, 2021, 6:47 PM
Got it, thanks mate
Dec 31, 2021, 6:49 PM
Extract mev maybe 🤔
Dec 31, 2021, 7:04 PM