BSC Testnet addLiquiditiyETH TRANSFER_FROM_FAILED

1.2k views Asked by At

I'm coding an bep20 token and if I want to add Liquidity with pancakeswap I get the following error: ProviderError: Error: VM Exception while processing transaction: reverted with reason string 'TransferHelper: TRANSFER_FROM_FAILED' Does anyone know why this is not working?

PancakeRouter address: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1 PancakeFactory address: 0x6725F303b657a9451d8BA641348b6761A6CC7a17

My addLiquidity function:

function addLiquidity() public payable {
        _approve(address(this), _pancakeRouterAddress, totalSupply());

        _pancakeRouter.addLiquidityETH(
            address(this),
            totalSupply(),
            0,
            0,
            address(this),
            block.timestamp
        );
    }

Hardhat fork: npx hardhat node --fork https://data-seed-prebsc-1-s1.binance.org:8545

Hardhat networks config:

networks: {
        localhost: {
            url: 'http://localhost:8545',
            chainId: 31337,
            forking: {
                url: " https://data-seed-prebsc-1-s1.binance.org:8545",
            }
        },
    },
1

There are 1 answers

0
tur461 On

Ensure two things when you add liquidity which uses transferFrom() function internally:

  • You have approved the spendor (here router)
  • you have at least the amount you have approved the spendor to spend