# transferFrom() not working to recieve ERC20 as payment

**URL:** <https://forum.openzeppelin.com/t/transferfrom-not-working-to-recieve-erc20-as-payment/29153>\
**Category:** Smart Contracts\
**Tags:** erc20, solidity, bep20\
**Created:** [May 28, 2022, 12:48am UTC](https://forum.openzeppelin.com/t/transferfrom-not-working-to-recieve-erc20-as-payment/29153 "2022-05-28T00:48:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luiscmogrovejo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/luiscmogrovejo/32/15062_2.png) [@Luiscmogrovejo](https://forum.openzeppelin.com/u/Luiscmogrovejo)\
**Post date:** [May 28, 2022, 12:48am UTC](https://forum.openzeppelin.com/t/transferfrom-not-working-to-recieve-erc20-as-payment/29153/1 "2022-05-28T00:48:42Z")

</div>

Hi Guys, I want to sell tokens and get other ERC20 token instead. I have put this function that works with the commented code but not with the transferFrom function. Does anyone can help me here?

```auto
function buyToken(uint _amountBUSD) public icoActive {
     require(whitelisted[msg.sender], "user not whitelisted");
     uint tokenAmount = ((((_amountBUSD*10**18)/3)*100));
     require(tokenAmount > 0, "Token amount 0");
     require((tokenAmount >= 1666000000000000000000) && (66666666666666666666667 >= tokenAmount), "Not between 50 or 2000 Busd");
     // int facuTokenPriceBNB = facuTokenPriceInBNB();
     // require(int(msg.value) >= facuTokenPriceBNB * int(_amount), "");
     require(token.balanceOf(address(this)) >= tokenAmount, "More than available on contract");
     require(boughtTokens[msg.sender] == false || sales[msg.sender].amount + tokenAmount <= 66666666666666666666667, "You only can buy 2000 Busd");
     // ethFunds.transfer(msg.value);
     ERC.transferFrom(msg.sender, ethFunds, (_amountBUSD*10**18));
     tokensSold += tokenAmount;
     sales[msg.sender] = Sale(msg.sender, tokenAmount, false);
     transaction[transactionCount] = Sale(msg.sender, tokenAmount, false);
     transactionCount++;
     boughtTokens[msg.sender] = true;
     emit Sell(msg.sender, (_amountBUSD*10**18));
 }
```

---

<div class="post-metadata">

**Author:** ![Team\_X](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/team_x/32/10471_2.png) [@Team\_X](https://forum.openzeppelin.com/u/Team_X)\
**Post date:** [May 29, 2022, 9:17am UTC](https://forum.openzeppelin.com/t/transferfrom-not-working-to-recieve-erc20-as-payment/29153/2 "2022-05-29T09:17:44Z")

</div>

have you approved the tokens to your contract?
