> 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="/files/9e8Sj08dBFpMOzDUMAPm" 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="/files/gi6M3wVLmDojBJBfHTrX" 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ankitavirani.com/experience/protocols/ercs-and-eips/erc-777.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
