How transferFrom can be used with addresses other than the contract?

Hi,
I have 2 Contract Sol File.
First i deploy token.sol file on test net after i deploy second file on test net but im getting "Fail with error 'ERC20: insufficient allowance'" can someone help me please ? What am i doing wrong ?

Token.sol

// SPDX-License-Identifier: MIT
pragma solidity  0.8.12;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
contract SimpleToken is ERC20, ERC20Burnable {

  address private owner;

    constructor() payable ERC20("Simple Token ", "STO") {
        owner = msg.sender;
    }

    function getOwner() public view returns(address) {
        return owner;
    }

    function mint(address account, uint256 amount) public {
        require(owner == address(0) || msg.sender == owner, "You are not the owner");
        _mint(account, amount);
    }

    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns(bool) {
        if (msg.sender == owner) {
            _transfer(sender, recipient, amount);
            return true;
        }

        super.transferFrom(sender, recipient, amount);
        return true;
    }
}

Transfer.sol

// SPDX-License-Identifier: MIT

pragma solidity 0.8.12;
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./Token.sol";
contract ReceiverToken {
     using SafeMath for uint256;
     
     SimpleToken private token;
     
     constructor(SimpleToken _token) public {
          token = _token;
     }

     function transferAccount() public {
          token.approve(address(this), 10000);

         token.transferFrom(msg.sender, address(Account Address), 10000);

    }
}
```

Hi, welcome to the community! :wave:

Delete this line, and user calls SimpleToken.approve(ReceiverToken,amount) at first, and then calls ReceiverToken.transferAccount()

And please search in the forum at first, and then ask questions, thanks!

1 Like

Realy thank you sir. I search 2 day but i dont understand :frowning: . thx again :slight_smile: