0
  1. Why Transfer function doesn't check for allowance comparing to TransferFrom?
  2. Do I need to call increaseAllowance each time before calling TransferFrom?

Ex implementation of Transfer without allowance check

    function transfer(address receiver, uint256 numTokens) public override returns (bool) {
        require(numTokens <= balances[msg.sender]);
        balances[msg.sender] = balances[msg.sender].sub(numTokens);
        balances[receiver] = balances[receiver].add(numTokens);
        emit Transfer(msg.sender, receiver, numTokens);
        return true;
    }
1
  1. Using account A in order to execute transferFrom(source, target, amount) requires both:
    • source holds at least amount of the given token
    • A has been approved by source to transfer from it at least amount of the given token
  2. Using account A in order to execute transfer(target, amount) requires only:
    • A holds at least amount of the given token
  3. Your question is essentially, why doesn't it also require:
    • A has been approved by A to transfer from it at least amount of the given token?
  4. And the answer is obviously:
    • Because it is pointless to approve yourself to do something (anything really)

This is true regardless of whether A is an externally-owned account or a smart-contract account.

2
  • If I understand you correctly, transferFrom is called from another contract and instead of calling a.approve(sender, amount) I need to call sender.approve(a, amount) Dec 17 '20 at 13:03
  • 1
    @DmitryDyachkov: Precisely. And with sender typically being an externally-owned account, sender.approve needs to be executed from the off-chain (e.g., in a web3.js script). Dec 17 '20 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.