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:

🧠 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:

💻 Implementation Details

Core Interface (IERC777)

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)

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

Recipient Hook Interface (IERC777Recipient)

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:

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.

Last updated

Was this helpful?