"Execution reverted with reason: STF" on Pancakeswap BSC Testnet. Works on Goerli

9.6k Views Asked by At

I am testing a smart contract that has a auto LP fee feature which means that the smart contract calls these two functions inside the _transfer function every 5 sells:

function swapTokensForETH(uint256 tokenAmount) private {
    address[] memory path = new address[](2);
    path[0] = address(this);
    path[1] = uniswapV2Router.WETH();
    _approve(address(this), address(uniswapV2Router), tokenAmount);
    uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
        tokenAmount,
        0, 
        path,
        address(this),
        block.timestamp
    );
}

function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
    // approve token transfer to cover all possible scenarios
    _approve(address(this), address(uniswapV2Router), tokenAmount);

    // add the liquidity
    uniswapV2Router.addLiquidityETH{value: ethAmount}(
        address(this),
        tokenAmount,
        0, // slippage is unavoidable
        0, // slippage is unavoidable
        address(0), // send LP token to burn address
        block.timestamp
    );
}

I deployed it on both Goerli and BSC Testnet. On goerli it works like a charm, distributing fees properly.

On pancakeswap, fees are accumulating but it's now impossible to sell because it is returning this error message: "Unknown error: "Execution reverted with reason: STF.". Try increasing your slippage tolerance."

Increasing slippage doesn't help in that case.

When I try to access the pair using the getPair function from the router it return 0, meaning that the pair is not set properly: router: https://testnet.bscscan.com/address/0xb7926c0430afb07aa7defde6da862ae0bde767bc#readContract Pair: https://testnet.bscscan.com/token/0xe0c59ff1482ba0768188fb82357b7187a74d0aac#readContract

We can see reading the token0 and token1 view functions from the pair smart contract that the two addresses are BNB and my ERC20 token. However I can't fetch the pair address from the router getPair function.

I think that is the reason why my contract can't call these two functions properly. But why is it so? But working fine on Goerli? Would mainnet give me the same trouble?

PS: Liquidity is added on V2 so it's supporting fees on transfers.

1

There are 1 best solutions below

0
On

The error you're receiving 'STF' stands for Safe Transfer Failed. The majority of the time this is invoke it is related to approvals.

I can see that you contract internally has approved spending to the router. However, you also need to call Approve on you wallet to the smart contract that your wrote.