> 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-777.md).

# ERC-777

## 📜 ERC-777: Advanced Token Standard

ERC-777 is an Ethereum token standard that improves upon ERC-20 by introducing new features and capabilities. This page provides a comprehensive overview of its architecture, core concepts, user flow, and implementation details.

### 🏗️ Architecture

ERC-777 builds on the foundation of ERC-20 while introducing new functionalities. Here's a high-level overview of the architecture:

<figure><img src="https://4222757721-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ8enmdGTQxxu7PPuvM80%2Fuploads%2FV4fq3iA0iQEiSbB5Awgh%2Fimage.png?alt=media&amp;token=664a8a4d-1dd2-47d6-b969-e10320f02a08" alt=""><figcaption></figcaption></figure>

### 🧠 Core Concepts

#### 1. Operators 👥

Operators are addresses authorized to send tokens on behalf of a token holder. This concept enhances flexibility in token management.

#### 2. Send Function 📤

The `send` function replaces the `transfer` function from ERC-20, providing more control and functionality.

#### 3. Hooks 🎣

ERC-777 introduces hooks that are called before sending and after receiving tokens, allowing for more complex interactions.

#### 4. Backwards Compatibility 🔄

ERC-777 tokens are backwards compatible with ERC-20, ensuring interoperability with existing systems.

### 🚶 User Flow

Here's a typical user flow for interacting with ERC-777 tokens:

<figure><img src="https://4222757721-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ8enmdGTQxxu7PPuvM80%2Fuploads%2FevsMiKMqyJwiDf6kOOMM%2Fimage.png?alt=media&amp;token=df8cfd62-59d1-4dee-a06c-0beeea55cb34" alt=""><figcaption></figcaption></figure>

### 💻 Implementation Details

#### Core Interface (IERC777)

```solidity
interface IERC777 {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function granularity() external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function balanceOf(address owner) external view returns (uint256);
    function send(address recipient, uint256 amount, bytes calldata data) external;
    function burn(uint256 amount, bytes calldata data) external;
    function isOperatorFor(address operator, address tokenHolder) external view returns (bool);
    function authorizeOperator(address operator) external;
    function revokeOperator(address operator) external;
    function defaultOperators() external view returns (address[] memory);
    // ... events
}
```

#### Sender Hook Interface (IERC777Sender)

```solidity
interface IERC777Sender {
    function tokensToSend(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external;
}
```

#### Recipient Hook Interface (IERC777Recipient)

```solidity
interface IERC777Recipient {
    function tokensReceived(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata userData,
        bytes calldata operatorData
    ) external;
}
```

### 🚀 Example Implementation

Here's a basic implementation of the ERC-777 standard:

```solidity
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC777/ERC777.sol";

contract MyERC777Token is ERC777 {
    constructor(
        string memory name,
        string memory symbol,
        address[] memory defaultOperators
    )
        ERC777(name, symbol, defaultOperators)
    {
        // Mint initial supply to the contract deployer
        _mint(msg.sender, 1000000 * 10**18, "", "", true);
    }

    // Additional custom functions can be added here
}
```

This implementation uses OpenZeppelin's ERC777 contract as a base, which provides a robust and secure implementation of the standard. Developers can extend this base implementation to add custom functionality specific to their use case.

### 🔍 Key Differences from ERC-20

* 📤 `send` function replaces `transfer` and `transferFrom`
* 🎣 Hooks allow for more complex token interactions
* 👥 Operator concept for enhanced authorization
* 🔥 Built-in burning functionality
* 🔢 Granularity for fractional tokens

ERC-777 provides a more feature-rich and flexible token standard compared to ERC-20, while maintaining backwards compatibility. This makes it an attractive option for projects requiring advanced token functionality.
