-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
swapExactTokensForETHSupportingFeeOnTransferTokens fails when from == uniswapPair address #117
Comments
Hi Italo,
did you delete your comment? I cannot see it on GitHub anymore.
Did you manage to find a solution for it?
…On Mon, 2 May 2022, 15:24 Ítalo Honorato, ***@***.***> wrote:
We're having the same problem.
swapExactTokensForTokensSupportingFeeOnTransferTokens doesn't want to
work when we sell tokens. It works on purchase and it works if we interact
with the UniswapV2Router02 contract directly through etherscan.
Test network: rinkeby.
Code:
` function swap(address _tokenIn, address _tokenOut, uint256 _amountIn,
uint256 _amountOutMin, address _to) external {
IERC20(_tokenIn).transferFrom(msg.sender, address(this), _amountIn);
IERC20(_tokenIn).approve(UNISWAP_V2_ROUTER, _amountIn);
address[] memory path;
if (_tokenIn == WETH || _tokenOut == WETH) {
path = new address[](2);
path[0] = _tokenIn;
path[1] = _tokenOut;
} else {
path = new address[](3);
path[0] = _tokenIn;
path[1] = WETH;
path[2] = _tokenOut;
}
IUniswapV2Router02(UNISWAP_V2_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(_amountIn, _amountOutMin, path, _to, block.timestamp);
}
`
I already tried with _amountOutMin but it also gives the same error as TransferHelper:
TRANSFER_FROM_FAILED.
—
Reply to this email directly, view it on GitHub
<#117 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHX4L6JTWDLFNQX7BTNSEO3VH7JQRANCNFSM5PXD7ZVQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Yes I made it, Below is the solution to this famous error. See if it helps you solve your problem: Basically the error happens because it is not possible to approve a permission for the UNISWAP_V2_ROUTER to spend tokens from the ContractSwapOnUniswap address, why by default the ERC20 approve function will not recognize ContractSwapOnUniswap as msg.sender . That is, the TransferHelper: TRANSFER_FROM_FAILED error occurs because the UNISWAP_V2_ROUTER does not have the necessary permission in the token contract to spend balance of ContractSwapOnUniswap . It concludes that this is a design error of the ERC20 standard itself applied to contracts that make exchanges from other accounts. If I'm wrong, please correct me. Does anyone know how to guide me on how to open a discussion on the subject, for possible improvements in this? |
|
I want to apply a fee of the 10% every time my token is transferred (except the case the from is the owner).
When i use PancakeSwap I'm able to create a pool, however, when I try to swap the token from the just created pool, I receive the error 'Pancake: TRANSFER_FAILED'
This happen when the from filed is equal to the _uniswapV2Pair address.
Why this happens and how to fix this problem?
The token code below:
The text was updated successfully, but these errors were encountered: