'BSC Testnet addLiquiditiyETH TRANSFER_FROM_FAILED
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",
}
},
},
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | tur461 |