0

I was curious after reading this article how ERC-223 protocol for token accomplishes this: ERC20 vs ERC223. List of differences

Energy savings. The transfer of ERC-223 tokens to a contract is a one step process rather than 2 step process (for ERC-20), and this means 2 times less gas and no extra blockchain bloating.

----------------------->

How does ERC-223 accomplish in one step subtracting the value from the sender and then add the value to the receiver?

1 Answer 1

2

If the recipient is a contract it invokes a callback function after making the transfer of tokens

function transfer(address _to, uint _amount, bytes _data) public {

    // Standard transfer
    balances[msg.sender] = balances[msg.sender].sub(_amount);
    balances[_to] = balances[_to].add(_amount);

    // If recipient is a contract invoke token callback function
    if (isContract(_to)) {

        // Cast to interface
        TokenRecipient(_to).tokenFallback(msg.sender, _amount, _data);
    }

    // Notify event
    Transfer(msg.sender, _to, _amount, _data)
}

The TokenRecipient is a simple interface contract

contract TokenRecipient {
    function tokenFallback(address _from, uint _amount, bytes _data) public;
};

In case of doubts read the recommended implementation.


Having a single call should use less gas than two but I doub't you will reduce your gas cost in half, usually the approve call is cheap and is the only thing you will save.

One important benefit is you gain atomicity of the operations. With ERC-20 at least two steps are required to interact with a contract which can lead to a race condition, if the second operation fails you have to undo the approve which will be a third transaction. But with an ERC-223 token those two steps are atomic, if one of those fails the whole transaction is reversed.

3
  • Thanks @Ismael! So if I understand correctly, ERC223 transfer to contract consumes half as much gas as ERC20 approve and transferFrom at receiver contract.
    – Bibyts
    Commented Nov 26, 2017 at 22:38
  • So for transfer of token there's only one function call for Transfer in ERC223 instead of two function calls in ER20?
    – Bibyts
    Commented Nov 26, 2017 at 22:39
  • @golddigger I think the gas consumption will be lower but only very modest. The extra suppressed call to approve is usually cheap.
    – Ismael
    Commented Nov 27, 2017 at 2:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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