> For the complete documentation index, see [llms.txt](https://www.ankitavirani.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.ankitavirani.com/experience/protocols/ercs-and-eips/erc-223.md).

# ERC-223

## ERC-223: An Enhanced Token Standard

### Introduction

ERC-223 is a token standard for Ethereum, proposed as an improvement to the widely used ERC-20 standard. It introduces mechanisms to address critical shortcomings of ERC-20, such as accidental token losses and inefficient gas usage. By defining a new communication model for token transfers, ERC-223 provides a more robust and user-friendly framework for token interactions.

***

### What is ERC-223?

ERC-223 is similar to ERC-20 but extends its functionality by:

* Handling token transfers on the recipient's side.
* Preventing the loss of tokens sent to incompatible contracts.
* Supporting metadata in token transfers for additional transaction context.

***

### Key Features and Differences

#### Improvements Over ERC-20

1. **Recipient Awareness**
   * ERC-223 tokens can only be transferred to contracts that implement the `tokenReceived` function.
   * Prevents tokens from being permanently lost if sent to non-compatible contracts.
2. **Efficient Transactions**
   * Uses a single `transfer` method instead of separate `approve` and `transferFrom`.
   * Reduces gas consumption by eliminating unnecessary calls.
3. **Metadata Support**
   * Allows metadata to be included with transfers, enabling context-specific actions.

***

### Workflow Diagram

<figure><img src="https://4222757721-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ8enmdGTQxxu7PPuvM80%2Fuploads%2FLpuYJCJcoc2c88XJAKr3%2FScreenshot%202025-01-20%20at%206.38.58%E2%80%AFPM.png?alt=media&amp;token=918515c2-fd0e-4e91-b94c-c92561e0b10d" alt=""><figcaption></figcaption></figure>

***

### ERC-223 Implementation

An ERC-223 token must define specific methods and events, as described in [EIP-223](https://eips.ethereum.org/EIPS/eip-223).

#### Required Methods

```solidity
function name() public view returns (string);
function symbol() public view returns (string);
function decimals() public view returns (uint8);
function totalSupply() public view returns (uint256);
function balanceOf(address _owner) public view returns (uint256 balance);
function transfer(address _to, uint256 _value) public returns (bool success);
function transfer(address _to, uint256 _value, bytes calldata _data) public returns (bool success);
```

#### Events

```solidity
event Transfer(address indexed _from, address indexed _to, uint256 _value, bytes calldata _data);
```

#### Recipient Contract Requirements

Contracts receiving ERC-223 tokens must implement:

```solidity
function tokenReceived(address _from, uint _value, bytes calldata _data);
```

If the recipient contract does not implement this function, the transaction fails, and tokens remain with the sender.

***

### Example Implementation

#### ERC-223 Token Contract

```solidity
pragma solidity ^0.8.19;

abstract contract IERC223Recipient {
    function tokenReceived(address _from, uint _value, bytes memory _data) public virtual;
}

contract ERC223Token {
    event Transfer(address indexed from, address indexed to, uint value, bytes data);
    mapping(address => uint256) private balances;

    function transfer(address _to, uint _value, bytes calldata _data) public returns (bool success) {
        balances[msg.sender] -= _value;
        balances[_to] += _value;
        if (isContract(_to)) {
            IERC223Recipient(_to).tokenReceived(msg.sender, _value, _data);
        }
        emit Transfer(msg.sender, _to, _value, _data);
        return true;
    }

    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly { size := extcodesize(account) }
        return size > 0;
    }
}
```

#### Recipient Contract

```solidity
pragma solidity ^0.8.19;

contract RecipientContract is IERC223Recipient {
    event Deposit(address indexed sender, uint value);
    uint256 public deposits;

    function tokenReceived(address _from, uint _value, bytes memory _data) public override {
        deposits += _value;
        emit Deposit(_from, _value);
    }
}
```

***

### Advantages of ERC-223

* **Safety**: Tokens cannot be accidentally lost by sending them to incompatible contracts.
* **Efficiency**: Reduces gas costs by requiring fewer transactions.
* **Extensibility**: Supports metadata for enhanced functionality.

***

### Limitations

* **Adoption**: ERC-223 is not yet widely adopted, limiting compatibility.
* **Backward Compatibility**: Existing ERC-20 tools and contracts require modifications to support ERC-223.
* **Gas Costs**: The additional recipient checks may increase transaction costs in some scenarios.
