Reputation: 21
I have a function to claim an accumulated token amount like below. But its throwing TRANSFER_FROM_FAILED. What is the safest way to do this?
function claimAccumulatedAmount() public {
_swapForBNB(_msgSender(), _msgSender(), getAccumulatedAmount(_msgSender()));
}
function _swapForBNB(address spender, address recipient, uint256 amount) internal {
_approve(spender, address(swapRouter), amount);
swapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
amount,
0, // slippage is unavoidable
sellPath,
recipient,
block.timestamp
);
}
Upvotes: 1
Views: 207
Reputation: 21
Found solution; Transfer tokens to address(this) and approve router then make the swap.
Upvotes: 1