1

The scenario is to transfer from Address B to Address C, deducting the transaction fee from Address.

Here A will have some ether amount, which should be used to deduct the gas.

The ERC20 Token Standard, has a method transferFrom, which takes from, to and amount as input.

What is the point of from here, does it always has to be the person signing the transaction (if so, then what's the reason behind having two method transfer and transferFrom)? Or it can be a different address?

1

The transferFrom method will only work if the owner (the _from address) has allowed the receiver ( _to address) to withdraw the funds, this is done by calling function approve(address _spender, uint256 _value) .

The address calling the transfer (or transferFrom) function will be the one paying the gas for the operation.

Hence, if B call approve(address_C, 10) , there will be no fund transfer but B will still have to pay some gas for this operation.

Then, A can call transferFrom(address_B, address_C, 10) and send fund from B to C, and only A will be paying gas for the transaction fees.

1

I agree with @Betcheg answer, but both A and B must have ether to invoke transferFrom and approve transactions, respectively.

But is there a way, such that only A need to have ether. And so B and C would have only tokens, not ether?

One way that I imagine is to change the "normal" way to implement a ERC20 token. For example, change tranferFrom method to give permition to an address, like the owner (or another person/address), to be able to call transferFrom method even if not at approved list:

function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
    require(_value <= allowed[_from][msg.sender] || msg.sender == owner);     // Check allowed
    allowed[_from][msg.sender] -= _value;

    //Other require validations

     balances[_from] -= _value;
    // Add the same to the recipient
    balances[_to] += _value;

    emit Transfer(_from, _to, _value);

    return true;
}

Or create a complete new method transferByOwner that is independent of allowence:

function transferByOwner(address _from, address _to, uint256 _value) public returns (bool success) {
    require(msg.sender == owner); 

    //Other require validations

     balances[_from] -= _value;
    // Add the same to the recipient
    balances[_to] += _value;

    emit Transfer(_from, _to, _value);

    return true;
}

Though, one can reply that this give the owner full control to all token balances. Sure that's exactly right :)

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.