I am unsuccessful trying to create an LP pair with IUniswapV2Factory and adding tokens to with IUniswapV2Router's addLiquidityETH or addLiquidity programmatically (via ethersjs).
I have ensured that both the tokens I am trying to add have approval allowances. But continually getting the error:
Error: VM Exception while processing transaction: reverted with reason string 'TransferHelper: TRANSFER_FROM_FAILED'
Below is my ethersjs code I am using:
// APPROVE A TOKENS
const txA = await aContract.approve(deployer.address, BigNumber.from("0x16345785D8A0000"));
console.log("https://ftmscan.com/tx/" + txA.hash);
await txA.wait();
// APPROVE B TOKEN
const tx1 = await bContract.approve(deployer.address, BigNumber.from("0x16345785D8A000"));
console.log("https://ftmscan.com/tx/" + tx1.hash);
await tx1.wait();
// CREATE SPOOKY LP PAIR
const tx = await spookyFactoryContract.createPair(
aContract.address,
bContract.address,
);
console.log("https://ftmscan.com/tx/" + tx.hash);
await tx.wait();
// GET SPOOKY LP PAIR
const pair = await spookyFactoryContract.getPair(
aContract.address,
bContract.address,
);
console.log("a/b " + pair);
Then upon trying to add liquidity with:
// ADD A AND B TOKENS TO SPOOKY LP PAIR
const tx1 = await spookyRouterContract.addLiquidity(
aContract.address,
bContract.address,
BigNumber.from("0x16345785D8A00"),
BigNumber.from("0x16345785D8A00"),
BigNumber.from("0x16345785D8A00"),
BigNumber.from("0x16345785D8A00"),
deployer.address,
BigNumber.from("0x621df7f5000"),
);
console.log("https://ftmscan.com/tx/" + tx1.hash);
await tx1.wait();
I get the error mentioned above:
Error: VM Exception while processing transaction: reverted with reason string 'TransferHelper: TRANSFER_FROM_FAILED'
I know that the creating LP pair isn't necessary as it is internal to the UniswapRouterV2's addLiquidity but just for completeness I am showing it. Thanks for your help.