ERC-777 is an advanced token contract standard designed to enhance security and functionality beyond older standards like ERC-20. It allows contract creators, token holders, and recipients to extend its capabilities without modifying the core token contract itself. By building on ideas from ERC-20 and ERC-223, ERC-777 introduces powerful features for developers and users alike.
Understanding Token Contracts
A token contract is a smart contract that maintains a mapping of account addresses to their respective balances. These balances represent value as defined by the contract creator—this could be physical assets, currency, or reputation. A single unit of balance is commonly referred to as a token.
End-users may control multiple addresses for various reasons, such as organizing tokens into different logical accounts (e.g., savings, taxes, expenses) or representing distinct sources of tokens (e.g., ICOs, investments, service fees). Each time tokens move between accounts, the contract updates the balances accordingly.
New tokens can be minted to increase the total supply, often by the contract owner. Conversely, tokens can be burned to reduce the supply if the contract permits it. While simple contracts use a basic address-to-balance mapping, more complex scenarios like dividends may require advanced structures.
The Role of Operators in ERC-777
ERC-777 introduces the concept of operators—third parties authorized to transfer tokens on behalf of token holders. Operators possess significant power, so they should be added cautiously.
Each address has a list of authorized operators. For example, an address might have two operators, while another has one. Some addresses may have no operators at all.
A practical use case involves managing multiple addresses holding different assets. Normally, transferring tokens requires the sending address to hold ETH for gas fees. This often involves multiple transactions: first sending ETH to the sender’s address, then executing the token transfer. With an operator, a single address holding ETH can handle token transfers for other addresses holding tokens, simplifying the process and improving user experience.
Operators can also be contracts (known as "token operator contracts"). These can be predefined for all holders during contract creation, enabling added functionality without altering the token contract itself.
Defining an ERC-777 Token Contract
Every ERC-777 token contract deployed on Ethereum has a unique address. Key parameters define its operation:
- Name: A human-readable identifier for the contract (e.g., "My Token"). While length isn’t restricted, shorter names are preferable for compatibility with wallet applications.
- Symbol: A short ticker symbol (e.g., "MYT"), typically 3–4 characters long.
- Granularity: The smallest divisible unit of the token. Since Solidity doesn’t support decimals, ERC-777 represents values internally as integers multiplied by 10^18. For example, 1.2345 tokens are stored as 1.2345 × 10^18. Granularity allows creators to limit divisibility—e.g., a license token might use a granularity of 10^18 (indivisible units), while a gold-backed token might use 10^16 (minimum unit of 0.01).
Unlike ERC-20, which uses adjustable decimal places, ERC-777 fixes the decimal position, making UI representation more straightforward.
Core Functions of ERC-777
ERC-777 provides several functions for managing tokens:
totalSupply(): Returns the total number of tokens in existence.balanceOf(address): Returns the balance of a specific address.send(amount, recipient): Transfers tokens from the sender to another address.burn(amount): Destroys tokens from the sender’s balance.authorizeOperator(operator): Grants an address operator privileges for the sender’s tokens.revokeOperator(operator): Removes an operator’s privileges.isOperatorFor(operator, holder): Checks if an address is an operator for a holder.operatorSend(holder, recipient, amount): Allows an operator to send tokens on behalf of a holder.defaultOperators(): Returns a list of default token operator contracts.
Events in ERC-777
ERC-777 defines events to track contract activity:
Minted(amount, recipient): Triggered when new tokens are created.Burned(amount, holder): Triggered when tokens are destroyed.Sent(amount, holder, recipient, operator): Triggered when tokens are transferred.AuthorizedOperator(operator, holder): Triggered when an operator is authorized.RevokedOperator(operator, holder): Triggered when an operator is revoked.
The Enhanced Send Process
Sending ERC-777 tokens involves a refined process:
- Validation: Check parameters, ensure sufficient balance, and verify the amount is a multiple of granularity.
- Authorization: Confirm the sender is either the holder or an authorized operator.
- Pre-transfer Hook: Call
tokensToSend()on the sender’s contract (if defined). - Transfer: Update balances.
- Post-transfer Hook: Call
tokensReceived()on the recipient’s contract (if defined). - Logging: Emit a
Sentevent.
The tokensToSend() and tokensReceived() hooks allow senders and receivers to implement custom conditions and actions. For example, a company’s CFO could encode rules into a token control contract, restricting how operators spend funds. Similarly, a recipient could automate invoice matching upon receiving payments.
Token Operator Contracts
Token operator contracts extend functionality without modifying the core token contract. For instance, a batch transfer operator could enable sending multiple tokens in one transaction. These contracts can be set as default operators during token deployment or added later by holders.
Operator contracts enable features like:
- Fee-less transfers
- Token swaps (e.g., for ICOs)
- Conditional transfers (e.g., time-locked releases)
Token Control Contracts vs. Operator Contracts
While both enhance functionality, key differences exist:
- Operator Contracts: Optional, callable by anyone, focus on extending capabilities.
- Control Contracts: Mandatory for hooks, callable only during transfers, focus on regulating token flow.
Compatibility with ERC-20
ERC-777 is designed to be backward-compatible with ERC-20. The same contract can implement both standards, using functions like transfer() (ERC-20) and send() (ERC-777) interchangeably.
Frequently Asked Questions
What is the main advantage of ERC-777 over ERC-20?
ERC-777 improves security and functionality with features like operators and transfer hooks, reducing risks like lost tokens and enabling advanced use cases without contract modifications.
How does granularity work in ERC-777?
Granularity defines the smallest token unit. Most tokens use 1 (divisible to 10^-18), but creators can set higher values to limit divisibility for assets like licenses or physical goods.
Can ERC-777 tokens interact with existing ERC-20 wallets?
Yes, through backward compatibility. However, advanced features like hooks require support from the wallet or contract.
What are default operators?
Default operators are pre-authorized contracts that provide added functionality (e.g., batch transfers) for all token holders upon deployment.
Is tokensReceived() mandatory?
For contract recipients, yes—this ensures tokens are only sent to contracts capable of handling them. For externally owned accounts, it’s optional.
How do I create an ERC-777 token?
Use the reference implementation provided in the standard, and consider testing with tools like Remix or Truffle. Always audit your code for security. 👉 Explore advanced token development strategies
Conclusion
ERC-777 represents a significant evolution in token standards, offering enhanced security, flexibility, and usability. Its operator model and transfer hooks enable complex workflows while maintaining compatibility with ERC-20. As the ecosystem grows, ERC-777 is poised to support innovative applications in DeFi, governance, and beyond.