Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article covers ERC777, which proposes a standard interface and behavior for token contracts while maintaining compatibility with ERC20.

The explanation below translates, summarizes, and expands on the following specification.

Overview

This EIP proposes a standard interface for token contracts. It provides more features and flexibility for handling tokens while maintaining compatibility with the existing ERC20 standard.

The proposal includes the following features.

Delegated token sending (operator functionality)

The proposal defines a mechanism for allowing other users or contracts to send tokens on your behalf. For example, a friend acting as your operator could send your tokens without requesting additional permission for each transfer.

Greater control over tokens (sending and receiving hooks)

Token holders can register hooks that perform specific actions when tokens are sent or received. For example, receiving tokens can automatically trigger another action.

Use of ERC1820

The proposal uses a mechanism called ERC1820. This makes it easier to notify the contract or address to which tokens are sent. It also allows integration with previously deployed contracts.

In summary, this EIP proposes a way to let other parties send tokens on a holder's behalf and configure custom actions when tokens are sent or received. Compatibility with older standards is also taken into account.

Motivation

This standard aims to improve the existing ERC20 token standard. Its main benefits are as follows.

  1. A consistent transfer model The proposed standard follows the same philosophy as Ether transfers. Tokens can be sent using send(dest, value, data).

  2. Control over outgoing token transfers Both contracts and ordinary addresses can register a tokensToSend hook to control outgoing tokens and reject transfers when necessary by raising an error in the hook function.

  3. Control over incoming tokens Both contracts and ordinary addresses can register a tokensReceived hook to control incoming tokens and reject transfers when necessary by raising an error in the hook function.

  4. Transfer and notification in one operation The tokensReceived hook allows tokens to be sent to a contract while notifying it in the same operation. This avoids the two separate calls (approve and transferFrom) required by ERC20.

  5. Authorizing and revoking operators Token holders can authorize or revoke operators that send tokens on their behalf. These operators may be specific contracts, such as exchanges, check-processing systems, or automated billing systems.

Operators Operators may be specific contracts such as exchanges, check-processing systems, or automated billing systems.

A token holder can authorize a particular contract as an operator capable of sending tokens on their behalf. This is useful when trading on an exchange or processing automated payments. Consider the following examples.

  1. Exchanges When a token holder trades tokens on an exchange, the exchange may need to send those tokens on the holder's behalf. The exchange is recognized as an operator and can move tokens without obtaining the holder's permission for every operation.

  2. Check-processing systems Suppose a contract operates a system that processes check-like payments. A token holder can similarly authorize this system as an operator, enabling automated payments.

  3. Automated billing systems The same applies to systems that automatically pay monthly subscription or usage fees. By granting a specific contract operator privileges, the holder can arrange for tokens to be sent and fees paid automatically each month.

These operators enable automated token transfers and payment processing by allowing holders to grant sending authority to specific contracts.

  1. Use of transaction data and operator data Token transactions include data and operatorData fields for conveying information between holders and operators.

Token transactions provide a mechanism for exchanging information between a token holder and an operator, such as a particular contract. This mechanism uses two dedicated data fields, data and operatorData.

Consider the following examples.

  1. data Token holders and operators can include transaction-related information in the data field. This allows additional information about sending or receiving tokens to be conveyed. Examples include the purpose of the transaction or a detailed description.

  2. operatorData operatorData is a field through which an operator can provide information to the token holder when performing a token transaction. For example, the operator can communicate why the tokens need to be sent or provide additional details.

In summary, data and operatorData convey supplementary information about token transactions. They can include not only information about sending and receiving tokens but also the transaction's purpose, reason, and other details, improving transparency and flexibility.

  1. Compatibility with older wallets A proxy contract can implement the tokensReceived hook to maintain compatibility with older wallets that lack it.

Older wallets may not implement the new token standard's tokensReceived hook. However, tokens adopting the new standard can still be made usable with older wallets. This can be achieved by implementing the tokensReceived hook in a proxy contract.

A proxy contract mediates between an existing wallet and the contract performing the operation. The proxy implements the tokensReceived hook when interacting with tokens that follow the new standard. This allows older wallets to receive and process new-standard tokens appropriately.

The process works as follows.

  1. Creating a proxy contract To use tokens following the new standard, first create a proxy contract. Since the proxy implements the tokensReceived hook, it can handle interactions with the new tokens correctly.

  2. Interacting with an older wallet The older wallet interacts with the proxy contract instead of interacting directly with tokens that follow the new standard. The proxy's tokensReceived hook ensures that token sending and receiving are handled appropriately.

  3. The proxy contract's role The proxy bridges the gap between older wallets and the new tokens. Because the older wallet interacts with the proxy, its operations can conform to the new standard.

A proxy contract facilitates communication between older wallets and new tokens. It enables older wallets to handle tokens following the new standard appropriately, maintaining compatibility.

Specification

ERC777Token contract

javascript
interface ERC777Token {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function totalSupply() external view returns (uint256);
    function balanceOf(address holder) external view returns (uint256);
    function granularity() external view returns (uint256);

    function defaultOperators() external view returns (address[] memory);
    function isOperatorFor(
        address operator,
        address holder
    ) external view returns (bool);
    function authorizeOperator(address operator) external;
    function revokeOperator(address operator) external;

    function send(address to, uint256 amount, bytes calldata data) external;
    function operatorSend(
        address from,
        address to,
        uint256 amount,
        bytes calldata data,
        bytes calldata operatorData
    ) external;

    function burn(uint256 amount, bytes calldata data) external;
    function operatorBurn(
        address from,
        uint256 amount,
        bytes calldata data,
        bytes calldata operatorData
    ) external;

    event Sent(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256 amount,
        bytes data,
        bytes operatorData
    );
    event Minted(
        address indexed operator,
        address indexed to,
        uint256 amount,
        bytes data,
        bytes operatorData
    );
    event Burned(
        address indexed operator,
        address indexed from,
        uint256 amount,
        bytes data,
        bytes operatorData
    );
    event AuthorizedOperator(
        address indexed operator,
        address indexed holder
    );
    event RevokedOperator(address indexed operator, address indexed holder);
}
  1. Implementing the interface The token contract must implement the ERC777Token interface shown above. Its implementation must follow the specification below.

  2. Registering with ERC1820 The token contract must register its own address as implementing the ERC777Token interface through ERC1820. This is done by calling the ERC1820 registry's setInterfaceImplementer function. The token contract address is supplied as both the address and the implementer, and the keccak256 hash of ERC777Token (0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054) is supplied as the interface hash.

The token contract must register its own address as implementing the ERC777Token interface. This is achieved by calling setInterfaceImplementer on the ERC1820 registry. The specific procedure is as follows.

  1. Register the token contract address To register its own address as implementing ERC777Token, the token contract calls setInterfaceImplementer on the ERC1820 registry.

  2. Specify the address and implementer When calling setInterfaceImplementer, supply the following information.

    • address
      • The token contract address.
    • implementer
      • The same token contract address.
    • interface hash
      • The keccak256 hash of ERC777Token (0xac7fbab5f54a3ca8194167523c6753bfeb96a445279294b6125b68cce2177054).

The ERC1820 registry then records that the token contract address implements the ERC777Token interface. Other contracts and addresses can check interface information through ERC1820 when interacting with the token contract.

In summary, the token contract uses ERC1820 to register its address as implementing ERC777Token, providing accurate interface information to other contracts and addresses that interact with it.

  1. Enabling and disabling ERC777 functions If the contract provides a switch to enable or disable ERC777 functions, the token must register or unregister the ERC777Token interface for its contract address each time the switch is triggered. Unregistration is performed by calling setInterfaceImplementer. Specifically, use the token contract address as the address, the keccak256 hash of ERC777Token as the interface hash, and 0x0 as the implementer.

  2. Transaction amounts and balances When interacting with the token contract, all amounts and balances are treated as unsigned integers. Internally, all values are stored in units of 1E-18 of a token. One display unit (the unit shown to end users) corresponds to 10^18 internal units.

  3. Internal units and display units The internal unit resembles wei, while the display unit resembles ether. This is equivalent to the ERC20 decimals function returning 18. For example, if a user's balance is 500,000,000,000,000,000 (0.5 × 10^18), the user interface should display 0.5 tokens. To send 0.3 tokens, the user must call the contract with an amount of 300,000,000,000,000,000 (0.3 × 10^18).

  1. Use of unsigned integers All amounts and balances are treated as unsigned integers when interacting with the token contract. Unsigned integers cannot represent negative values; they represent only nonnegative integers. This allows accurate numerical processing in transactions and calculations.

  2. Use of internal units (1E-18) Internally, all token values are stored in units of 1E-18 of a token. This very small value represents the base unit of the token. It allows transactions and calculations involving fractional token amounts to use high precision.

  3. Understanding display units When displaying token balances or amounts to end users, internal units are converted into a more readable representation. One display unit equals 10^18 internal units. This presents token quantities in a form that end users can easily understand.

Consider a concrete example.

  • If a balance in internal units (1E-18) is 1000000000000000000 (one token), it is displayed to the end user as 1 token.
  • To send 0.5 tokens, the end user must specify 500000000000000000 internal units when calling the token contract.

In summary, internal units (1E-18) and display units (10^18 internal units) provide accurate, high-precision token operations and a readable representation for end users.

  1. User interfaces generated from the ABI User interfaces generated from a token contract's ABI may display amounts using internal units. However, this must be made explicit. For example, displaying the type as uint256 indicates that internal units are being used.

In summary, a token contract implements the ERC777Token interface according to the specification and registers itself through ERC1820. Amounts and balances use internal and display units, and a proxy contract can help maintain compatibility with older wallets.

Functions

name

Selector: 06fdde03

javascript
function name() external view returns (string memory)

Returns the token's name. For example, it may return MyToken.

symbol

Selector: 95d89b41

javascript
function symbol() external view returns (string memory)

Returns the token's symbol. For example, it may return MYT.

totalSupply

Selector: 18160ddd

javascript
function totalSupply() external view returns (uint256)

Returns the total supply of issued tokens. It must equal the sum of the balances of all addresses returned by balanceOf. It must also equal the sum of all tokens minted in Minted events minus the sum of all tokens burned in Burned events.

balanceOf

Selector: 70a08231

javascript
function balanceOf(address holder) external view returns (uint256)

Returns the token balance of a particular address. It must return a value of at least 0.

Arguments

  • holder
    • The address whose token balance is being queried.

granularity

Selector: 556f0dc7

javascript
function granularity() external view returns (uint256)

Returns the smallest indivisible unit of the token. Granularity is specified in internal units and defines the smallest quantity used when minting, sending, or burning tokens.

The following rules apply to granularity.

  1. Granularity is set when the token is created.
  2. Once set, granularity cannot be changed.
  3. Granularity is at least 1.
  4. Every balance is a multiple of granularity.
  5. Any token minting, sending, or burning operation must use a multiple of granularity. Operations involving amounts that are not multiples of granularity are invalid, and the transaction reverts.

⚠️ Note Most tokens should be fully divisible. Unless there is a reason to prohibit fractional token amounts, this function should normally return 1.

In summary, granularity returns the token's smallest unit and defines the unit used for minting, sending, and burning. This unit is an important property of the token and must be handled according to the rules. The decimals function is also important for ERC20 compatibility because it defines the number of decimal places.

Operators

An operator is an address authorized to send or burn tokens on behalf of a particular holder.

Operator authorization and events

  • When an address becomes an operator for a particular holder, an AuthorizedOperator event is emitted.
    • In the AuthorizedOperator event, the operator (topic 1) and holder (topic 2) are their respective addresses.
  • When a holder revokes an operator, a RevokedOperator event is emitted.
    • In the RevokedOperator event, the operator (topic 1) and holder (topic 2) are likewise their respective addresses.
  • Note
    • A holder can have multiple operators at the same time.

Default operators

  • A token may define default operators.
  • Default operators can automatically send or burn tokens on behalf of all holders.
  • Defining default operators does not emit an AuthorizedOperator event.
  • The following rules apply to default operators.
    • The token contract defines its default operators at creation.
    • Default operators must be immutable.
      • The token contract must not add or remove default operators.

General operator rules

  • An address must always be its own operator.
    • Therefore, an address cannot revoke itself as its own operator.
  • If an address is an operator for a particular holder, isOperatorFor returns true.
  • If an address is not an operator for a particular holder, isOperatorFor returns false.

Event emission

  • When a holder authorizes an address as an operator, an AuthorizedOperator event is emitted.
  • When a holder revokes an address as an operator, a RevokedOperator event is emitted.

⚠️ Note

  • A holder can authorize an already authorized operator again.
    • An AuthorizedOperator event is emitted each time.
  • A holder can revoke an already revoked operator again.
    • A RevokedOperator event is emitted each time.

AuthorizedOperator

javascript
event AuthorizedOperator(address indexed operator, address indexed holder)

Event emitted when an operator is authorized.

Parameters

  • operator
    • The operator address.
  • holder
    • The token holder's address.
    • The address that authorized the operator.

RevokedOperator

javascript
event RevokedOperator(address indexed operator, address indexed holder)

Event emitted when an operator is revoked.

Parameters

  • operator
    • The operator address.
  • holder
    • The token holder's address.
    • The address that revoked the operator's authorization.

To manage operators, the contract must implement the defaultOperators, authorizeOperator, revokeOperator, and isOperatorFor functions described below. The token contract may implement additional functions for managing operators.

defaultOperators

Selector: 06e48538

javascript
function defaultOperators() external view returns (address[] memory)

Returns the array of default operators. If no default operators exist, it returns an empty array.

authorizeOperator

Selector: 959b8c3f

javascript
function authorizeOperator(address operator) external

Authorizes an operator for the msg.sender address. The token holder (msg.sender) is always its own operator, and this right cannot be revoked. Therefore, if this function attempts to authorize the holder (msg.sender) as its own operator (that is, the operator equals msg.sender), the function reverts.

Arguments

  • operator
    • The address to authorize as an operator.

revokeOperator

Selector: fad8b32a

javascript
function revokeOperator(address operator) external

Revokes an operator's authority for the msg.sender address. The token holder (msg.sender) is always its own operator, and this right cannot be revoked. Therefore, if the function attempts to revoke the holder (msg.sender) as its own operator (that is, the operator equals msg.sender), the function reverts.

Arguments

  • operator
    • The address to revoke as an operator.

isOperatorFor

Selector: d95b6371

javascript
function isOperatorFor(
    address operator,
    address holder
) external view returns (bool)

Checks whether a particular address is an operator for a token holder's address.

Arguments

  • operator
    • The address to check for operator status.
  • holder
    • The token holder's address.

Return value A bool indicating whether the address is an operator for the token holder.

⚠️ Note To determine which addresses are operators for a particular holder, call isOperatorFor for each default operator using the holder's address and analyze the holder's AuthorizedOperator and RevokedOperator events.

Sending tokens

When an operator sends a specified amount of tokens with associated data and operator data from a holder to a recipient address, the token contract applies the following rules.

  1. Any authorized operator may send tokens to a recipient address other than 0x0.
  2. The token holder's balance decreases by the amount sent.
  3. The recipient's balance increases by the amount sent.
  4. The token holder's balance must remain at least 0 after the transfer. Check that the holder's balance before sending is sufficient for the amount to be sent.
  5. The token contract emits a Sent event.
  6. The operator may include information in the operator data.
  7. If the token holder has registered an ERC777TokensSender implementation through ERC1820, the token contract must call the holder's tokensToSend hook.

tokensToSend

This hook is a piece of custom code called by the token contract when the holder sends tokens. The holder can use it to run additional logic or processing before tokens are sent. For example, the holder can impose special conditions on sending tokens or include additional data in a transaction.

If the holder has registered a tokensToSend hook, the token contract calls it before performing the token send operation. The holder can perform the necessary processing or checks in the hook and determine whether the send should proceed. The token contract determines whether to execute the send operation based on the hook's result.

This lets holders customize additional logic for sending tokens, enabling more flexible token transactions.

  1. If the recipient address has registered an ERC777TokensRecipient implementation through ERC1820, the token contract must call its tokensReceived hook.
  2. The data and operator data used for the send must remain unchanged throughout the sending process. The same data and operator data are therefore used for both hook calls and the emission of the Sent event.

Sending tokens involves specific data and operator data. The token contract and related code use this information during the send operation. Crucially, the data must remain consistent and unchanged throughout the sending process.

For example, consider a holder sending tokens. The holder sends tokens to a particular recipient address and specifies the associated data and operator data. This data represents the information and processing details needed for the token send.

It is important that this data not change during the sending process. Changing the data supplied by the holder midway through the operation could produce unexpected results. For example, if data changes during a token send, inconsistencies in the details of the transfer may cause unexpected transaction behavior.

Therefore, the data and operator data must remain unchanged throughout the sending process. To achieve this, the same data and operator data are passed to the holder's tokensToSend hook, the recipient's tokensReceived hook, and the Sent event. This maintains consistency throughout the sending process and helps ensure reliable token transactions.

These rules clearly define the process by which operators send tokens, helping ensure reliable transactions.

The token contract must reject the send operation in any of the following cases.

  • The operator address is not authorized by the holder.
  • The holder's balance or the recipient's balance is not a multiple of the token's minimum unit as defined by the contract.
  • The recipient is a contract that does not implement ERC777TokensRecipient through ERC1820.
  • The holder or recipient address is 0x0.
  • Any balance would become negative (less than 0).
  • The holder's tokensToSend hook fails.
  • The recipient's tokensReceived hook fails.

A token contract may send tokens from multiple holders to multiple recipients, or vice versa. In such cases, the following conditions must be met.

  • The preceding sending rules apply to every holder and recipient address.
  • The sum of balance increases must equal the total amount of tokens sent.
  • The sum of balance decreases must equal the total amount of tokens sent.
  • A Sent event with the corresponding amount is emitted for each holder-recipient pair.
  • The sum of amounts in the Sent events must equal the total amount sent.

⚠️ Note

  • A mechanism that charges a fee on transfers is effectively a send to multiple recipient addresses.
    • If the transfer includes both the token destination and the fee recipient, it is considered a send to multiple addresses.
  • Token movements may be chained together as a sequence of actions.
    • For example, a contract may receive tokens and then send them to another address.
    • In this case, the preceding sending rules apply to each send individually.
    • Balances are increased or decreased and events emitted for each send, with each operation processed according to the rules.
  • Sending an amount of zero (0) is permitted and treated like an ordinary send.
    • No tokens actually move in this case, but the operation is still treated as necessary for normal transaction processing.

The token implementation requirements can be explained as follows.

  1. Order of calls to the tokensToSend and tokensReceived hooks When sending tokens, the token contract first calls the tokensToSend hook. This hook runs before the token movement. The holder's balance is then reduced and the recipient's balance increased by the amount sent. The tokensReceived hook is called afterward. This hook runs after the token movement.

  2. The data and operatorData fields When tokens are sent, the data field contains information supplied by the holder. It is similar to the data field of an ordinary ETH transfer transaction. Either or both of the tokensToSend() and tokensReceived() hooks may use this information to decide whether to accept or reject the transaction. The operatorData field serves a similar purpose, but its contents are supplied by the operator. The operator can use this field to communicate specific information. However, the recipient typically ignores operatorData or simply logs it when processing the operation.

These requirements define the order of sending operations, how data is supplied and processed, and how operators convey information, enabling reliable token transactions.

Sent event

javascript
event Sent(
    address indexed operator,
    address indexed from,
    address indexed to,
    uint256 amount,
    bytes data,
    bytes operatorData
)

Event emitted when an operator sends an amount of tokens from a source address to a destination address.

Parameters

  • operator
    • The operator address.
  • from
    • The token holder's address.
  • to
    • The token recipient's address.
  • amount
    • The amount of tokens sent.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

The send and operatorSend functions described below must be implemented to perform token sends. The token contract may also implement other functions for sending tokens.

send

Selector: 9bd9bbc6

javascript
function send(address to, uint256 amount, bytes calldata data) external

Sends an amount of tokens from the msg.sender address to address to.

Both the operator and the holder must be the same address as msg.sender.

Parameters

  • to
    • The token recipient's address.
  • amount
    • The amount of tokens to send.
  • data
    • Information supplied by the holder.

operatorSend

Selector: 62ad1b83

javascript
function operatorSend(
    address from,
    address to,
    uint256 amount,
    bytes calldata data,
    bytes calldata operatorData
) external

Sends a specified amount of tokens from address from to address to on the holder's behalf.

⚠️ Note The send operation reverts if the operator address is not an authorized operator for address from.

The from and msg.sender addresses may be the same. In other words, an address can call operatorSend on its own behalf. This call must be equivalent to a send, except that the operator can explicitly specify operatorData, which is not possible with the send function.

Parameters:

  • from
    • The token holder's address.
  • to
    • The token recipient's address.
  • amount
    • The amount of tokens to send.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

Minting tokens

Minting is the process of creating new tokens. ERC777 does not define a specific function for minting tokens. This allows flexible use of the standard because minting processes vary by token.

However, minting tokens to a recipient must follow these rules.

  • Tokens may be minted to any recipient address except 0x0.
  • The total supply increases by the amount minted.
  • The balance of address 0x0 must not decrease.
  • The recipient's balance must increase by the amount minted.
  • The token contract must emit a Minted event with the correct values according to the event definition.
  • If the recipient has registered an ERC777TokensRecipient implementation through ERC1820, the token contract must call the recipient's tokensReceived hook.
  • The data and operator data must remain unchanged throughout the minting process.
    • The same data and operator data are therefore used when calling tokensReceived and emitting the Minted event.

The token contract must abort the minting transaction in any of the following cases.

  • The recipient's balance after minting is not a multiple of the minimum unit defined by the token contract.
  • The recipient is a contract that does not implement the ERC777TokensRecipient interface through ERC1820.
  • The recipient address is 0x0.
  • The recipient's tokensReceived hook fails.

When the token contract is created, the initial supply is minted to the address or addresses receiving it. Therefore, at least one Minted event must be emitted, and the recipients' tokensReceived hooks must be called.

The ERC20 compatibility requirements are as follows.

  1. A Sent event must not be emitted when minting tokens. However, if the token contract is ERC20-compatible, it emits a Transfer event. The from parameter of this Transfer event is set to 0x0. This behavior is defined by the ERC20 standard.

  2. A token contract may mint tokens to multiple recipient addresses at once. In this case, the following rules apply.

    • The preceding minting rules apply to every recipient address.
    • The sum of all balance increases must equal the total amount minted.
    • A Minted event with the corresponding amount is emitted for each recipient.
    • The sum of all amounts in the Minted events must equal the total amount minted.
  3. Minting zero (0) tokens is treated like ordinary minting.

  4. Data is supplied by the holder when sending or burning tokens, but this does not apply when minting. In this case, the data may be supplied by the token contract or the operator. This allows tokens to be minted successfully to holders who expect specific data.

  5. The operatorData field contains information supplied by the operator. It is similar to the data field of an ordinary ETH transfer transaction. The tokensReceived() hook may use this information to decide whether to reject the transaction.

Minted event

javascript
event Minted(
    address indexed operator,
    address indexed to,
    uint256 amount,
    bytes data,
    bytes operatorData
)

Event emitted when an operator mints an amount of tokens to a recipient address.

Parameters

  • operator
    • The address that performed the minting operation.
  • to
    • The address receiving the tokens.
  • amount
    • The amount of tokens minted.
  • data
    • Information supplied regarding the recipient address.
  • operatorData
    • Information supplied by the operator.

Burning tokens

Burning is the act of destroying existing tokens. ERC777 explicitly defines two functions for burning tokens: burn and operatorBurn. These functions integrate the burning process into wallets and dApps. However, a token contract may prevent some or all holders from burning tokens for a particular reason. The token contract may also define other functions for burning tokens.

The following rules must be followed when burning a holder's tokens.

  • Tokens may be burned from any holder address except 0x0.
  • The total supply decreases by the amount burned.
  • The balance of 0x0 does not increase.
  • The holder's balance decreases by the amount burned.
  • The token contract emits a Burned event with the correct values, according to the event definition.
  • If the holder has registered an ERC777TokensSender implementation through ERC1820, the token contract must call the holder's tokensToSend hook.
  • operatorData must remain unchanged throughout the burning process.
    • Therefore, the same operatorData is used when calling the tokensToSend hook and emitting the Burned event.

The token contract must revert the transaction when burning tokens in any of the following cases.

  • The operator address is not an authorized operator for the holder.
  • The holder's balance after burning is not a multiple of the minimum unit defined by the token contract.
  • The holder's balance is less than the amount to be burned (that is, the holder's balance would become negative).
  • The holder's address is 0x0.
  • The holder's tokensToSend hook reverts the transaction.

ERC20 compatibility requirements A Sent event must not be emitted when burning tokens. However, if the token contract supports ERC20, it emits a Transfer event with the to parameter set to 0x0. Although the ERC20 standard does not define token burning, this is a generally accepted practice.

A token contract may burn tokens from multiple holders at once. In this case, the following rules apply.

  • The preceding burning rules apply to each holder.
  • The sum of all balance decreases must equal the total amount burned.
  • A Burned event with the corresponding amount is emitted for each holder.
  • The sum of all amounts in the Burned events must equal the total amount burned.
  • Burning zero (0) tokens is treated like an ordinary burn operation.
  • The data field contains information supplied by the holder, similar to the data field of an ordinary ETH transfer transaction.
  • Either or both of the tokensToSend() and tokensReceived() hooks can use this information to decide whether to reject the transaction.
  • The operatorData field resembles the data field, but its contents are supplied by the operator.

Burned event

javascript
event Burned(
    ddress indexed operator,
    address indexed from,
    uint256 amount,
    bytes data,
    bytes operatorData
);

Event emitted when an operator burns a specified amount of tokens from a holder address.

Parameters

  • operator
    • The address that performed the burn.
  • from
    • The address of the holder whose tokens were burned.
  • amount
    • The amount of tokens burned.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

burn

Selector: fe9d9303

javascript
function burn(uint256 amount, bytes calldata data) external

Burns a specified amount of tokens from msg.sender.

Arguments

  • amount
    • The amount of tokens to burn.
  • data
    • Information supplied by the holder.

operatorBurn

Selector: fc673c4f

javascript
function operatorBurn(
    address from,
    uint256 amount,
    bytes calldata data,
    bytes calldata operatorData
) external

Allows an operator to burn a specified amount of tokens belonging to the from address.

Note The burn operation reverts if the operator address is not an authorized operator for the from address. The operator may pass arbitrary information through operatorData. However, operatorData must be supplied only by the operator. The from and msg.sender addresses may be the same. In other words, an address may call operatorBurn on its own behalf. This call must be equivalent to the burn function, except that it also allows the operator to specify an explicit value for operatorData.

Parameters

  • from
    • The address of the holder whose tokens are to be burned.
  • amount
    • The amount of tokens to burn.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

ERC777TokensSender and the tokensToSend hook

ERC777TokensSender provides notifications of requests that decrease a particular holder's balance (sending and burning). Any address (an ordinary address or a contract) that wants to receive notifications when its token balance decreases may use ERC1820 to register the address of a contract implementing the ERC777TokensSender interface described below.

This is done by calling setInterfaceImplementer on the ERC1820 registry. Specify the holder's address as the address, the keccak256 hash of ERC777TokensSender (0x29ddb589b1fb5fc7cf394961c1adf5f8c6454761adf795e67fe149f658abe895) as the interface hash, and the address of the contract implementing ERC777TokensSender as the implementer.

Note An ordinary address can register a contract address as its implementer instead of registering itself. The designated contract must itself implement the following interface.

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

tokensToSend

Selector: 75ab9782

javascript
function tokensToSend(
    address operator,
    address from,
    address to,
    uint256 amount,
    bytes calldata userData,
    bytes calldata operatorData
) external

Notifies the holder of a request by a specified operator to send tokens from the from address to the to address, or to burn tokens when to is 0x0.

Parameters

  • operator
    • The address of the operator performing the token send or burn.
  • from
    • The address of the holder whose tokens are being sent.
  • to
    • The token recipient's address for a send, or 0x0 for a burn.
  • amount
    • The amount by which the holder's token balance decreases.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

The following rules apply when calling the tokensToSend hook.

  • The tokensToSend hook must be called for send and burn operations.
  • The tokensToSend hook is called before the state is updated.
    • In other words, it is called before the balance decreases.
  • operator is the address that triggered the send or burn operation.
  • from is the address of the holder whose tokens are being sent or burned.
  • to must be the token recipient's address for a send.
    • For a burn, it must be 0x0.
  • amount is the amount of tokens sent or burned by the holder.
  • data is any additional information supplied for the send or burn operation.
  • operatorData is additional information supplied by the address that triggered the balance decrease.

The holder may block the send or burn operation by reverting it (that is, the holder may reject token withdrawals from their account).

Note Multiple token holders may use the same ERC777TokensSender implementation. An address may register at most one implementation at any given time. Consequently, ERC777TokensSender must be implemented with the possibility that different token contracts may call it. The msg.sender of a tokensToSend call is expected to be the token contract's address.

ERC20 compatibility requirements This hook takes precedence over ERC20 and must be called before performing ERC20 transfer and transferFrom operations. When called from transfer, operator must be the same address as from. When called from transferFrom, operator must be the address that called transferFrom.

ERC777TokensRecipient and the tokensReceived hook

ERC777TokensRecipient provides notifications when a particular recipient address's balance increases (through sending or minting). Any address (an ordinary address or a contract) that wants to receive notifications when tokens are credited to it may use ERC1820 to register the address of a contract implementing the ERC777TokensRecipient interface described below.

This is done by calling setInterfaceImplementer on the ERC1820 registry. Specify the recipient address as the address, the keccak256 hash of ERC777TokensRecipient (0xb281fc8c12954d22544db45de3159a39272895b169a852b314f9cc762e44c53b) as the interface hash, and the address of the contract implementing ERC777TokensRecipient as the implementer.

javascript
interface ERC777TokensRecipient {
    function tokensReceived(
        address operator,
        address from,
        address to,
        uint256 amount,
        bytes calldata data,
        bytes calldata operatorData
    ) external;
}

If the recipient address is a contract that has not registered an ERC777TokensRecipient implementation, the token contract behaves as follows.

  • If the tokensReceived hook would be called from a mint or send operation, the token contract must revert.
  • If the tokensReceived hook would be called from an ERC20 transfer or transferFrom operation, the token contract continues processing the transaction.

Note An ordinary address may register the address of a contract implementing the interface on its behalf. A contract must register either its own address or another contract's address. The registered address must implement the interface on its behalf.

tokensReceived

Selector: 0023de29

javascript
function tokensReceived(
    address operator,
    address from,
    address to,
    uint256 amount,
    bytes calldata data,
    bytes calldata operatorData
) external

Notifies the recipient of a request by an operator to send a specified amount of tokens from the from address to the to address, or to mint tokens when from is 0x0. This function cannot be called outside the mint, send, or ERC20 transfer process.

Parameters

  • operator
    • The address of the operator that increased the token balance (through sending or minting).
  • from
    • The token holder's address (0x0 for minting).
  • to
    • The recipient address receiving the tokens.
  • amount
    • The amount by which the recipient's token balance increases.
  • data
    • Information supplied by the holder.
  • operatorData
    • Information supplied by the operator.

The following rules apply when calling the tokensReceived hook.

  • The tokensReceived hook must be called for all send and mint operations.
  • The tokensReceived hook is called after the state has been updated.
    • In other words, it is called after the balance increases.
  • operator is the address that triggered the send or mint operation.
  • For a send, from is the address of the holder whose tokens are being sent.
  • For minting, from is 0x0.
  • to is the recipient address receiving the tokens.
  • amount is the amount of tokens sent or minted to the recipient address.
  • data is additional information supplied for the send or mint operation.
  • operatorData is additional information supplied by the address that triggered the balance increase.
  • A token holder can block the send or mint operation by reverting it (that is, the holder can refuse to receive the tokens).

Note Multiple token holders may use the same ERC777TokensRecipient implementation. An address may register at most one implementation at any given time. Consequently, ERC777TokensRecipient must be implemented with the possibility that different token contracts may call it. The msg.sender that called tokensReceived is expected to be the token contract's address.

ERC20 compatibility requirements This hook takes precedence over ERC20 and must be called before completing ERC20 transfer and transferFrom operations. When called from transfer, operator must be the same address as from. When called from transferFrom, operator must be the address that called transferFrom.

Additional considerations

The ERC777 standard incorporates several important principles and concepts.

Addressing shortcomings while maintaining backward compatibility

ERC777 aims to address certain shortcomings of ERC20 while maintaining backward compatibility with it. ERC20 can present issues relating to token sending and a lack of precise information. ERC777 addresses these issues by introducing new features while supporting integration with existing applications and smart contracts.

A clearly defined lifecycle

ERC777 clearly defines the token lifecycle. It specifies in detail how tokens are handled, including creation (mint), sending, and destruction (burn). This maintains consistency in information about token value and circulation.

Use of data and operatorData

The data and operatorData fields can be used during token minting, sending, and burning. These fields provide more context by carrying information related to token movements. For example, senders or recipients can communicate specific information alongside a token movement.

Introduction of hooks

ERC777 introduces hooks to make token sending more efficient and flexible. Hooks customize actions associated with token movements. For example, a hook can perform a particular operation when tokens are received or check particular conditions when tokens are sent.

Greater control for holders

ERC777 provides mechanisms allowing holders to control token movements. Holders can accept or reject the sending of tokens to particular addresses. This gives holders more fine-grained control over token transactions.

Use of the ERC1820 registry

Holders can register hooks using the ERC1820 registry. This registry associates holders with contracts that customize processing related to token movements. This increases flexibility and facilitates integration with different tokens.

The operator concept

ERC777 introduces the concept of operators that can send tokens. Holders can designate operators to move their tokens to other addresses. Holders can also revoke operators at their discretion.

Backward compatibility

The ERC777 standard proposed by this EIP introduces new features and flexibility while maintaining backward compatibility with the existing ERC20 token standard.

Naming of sending and operator functions

ERC777 uses send and operatorSend to send tokens. The existing ERC20 standard uses transfer and transferFrom. This helps avoid confusion about which token standard is being used.

Implementing ERC20 functions

ERC777 permits the implementation of ERC20 functions such as transfer, transferFrom, approve, and allowance so that a token can be fully ERC20-compatible. This allows new features to be added while retaining existing ERC20 functions.

Implementing decimals

ERC777 tokens may implement the decimals() function to indicate the number of decimal places. This is optional and maintains backward compatibility with ERC20. If implemented, it must always return 18.

Implementing both standards

A token contract can implement ERC20 and ERC777 simultaneously. View functions such as name, symbol, balanceOf, and totalSupply, as well as internal data implementations, may be shared between the two standards. Although ERC777 requires functions such as name, symbol, balanceOf, and totalSupply, decimals is not part of the ERC777 standard.

Hook precedence

Even when ERC20 functions are implemented, the tokensToSend and tokensReceived hooks take precedence over them. Consequently, even when ERC20 transfer or transferFrom is called, the token contract checks through ERC1820 whether the from and to addresses implement the tokensToSend and tokensReceived hooks, respectively. If either hook is implemented, it must be called. A transfer call should still be accepted when a contract does not implement the tokensReceived hook, but the risk of tokens becoming locked is greater in this case.

Event emission

The ERC777 standard requires Sent, Minted, and Burned events to be emitted for token sends, minting, and burning, respectively. If the token contract implements the ERC20Token interface through ERC1820, it also emits a Transfer event when minting or burning. When sending tokens, a Transfer event must also be emitted (as defined by the ERC20 standard). Accordingly, an ERC20 Transfer event may be emitted alongside an ERC777 Sent, Minted, or Burned event for the same token movement. Developers must not interpret these events as separate token movements, but should handle them appropriately according to each standard.

Tests and reference implementation

They are available in the following GitHub repository.

References

Jacques Dafflon mail@0xjac.com, Jordi Baylina jordi@baylina.cat, Thomas Shababi tom@truelevel.io, "ERC-777: Token Standard," Ethereum Improvement Proposals, no. 777, November 2017. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-777.

Conclusion

This article covered ERC777, which proposes a standard token contract interface and behavior while maintaining compatibility with ERC20.