ERC-1820 · Final · ERC · 2019-03-04
ERC-1820: Pseudo-introspection Registry Contract
A single registry contract, at the same address on every chain, where any account or contract can declare which interfaces it supports and which contract implements them; ERC-777 relies on it.
What problem does it solve?
ERC-165 lets a contract answer "do you support interface X?", but only contracts can answer, and only about themselves. An externally owned account cannot say "I accept ERC-777 tokens, and contract Y handles that for me". Earlier attempts used reverse ENS, which was complex and controlled by a multisig.
ERC-1820 defines one global, ownerless registry. Any address can register an implementer contract for a named interface, and anyone can look that up. It supersedes ERC-820, which broke with Solidity 0.5's ERC-165 behaviour; otherwise the two are functionally the same.
How it works
- Interface names are hashed with keccak256. Standard names follow
ERC###Name, e.g.keccak256("ERC777TokensRecipient"). You may also invent your own names. - Register:
setInterfaceImplementer(addr, interfaceHash, implementer). Only the address's manager may call it; by default every address is its own manager. If the implementer is another contract, that contract must confirm by returningERC1820_ACCEPT_MAGIC(keccak256 of the string"ERC1820_ACCEPT_MAGIC") fromcanImplementInterfaceForAddress. A magic value is used instead oftrueso a contract with a permissive fallback cannot accidentally "accept". - Look up:
getInterfaceImplementer(addr, interfaceHash)returns the implementer or zero. - ERC-165 bridge: hashes whose last 28 bytes are zero are treated as ERC-165 IDs. The registry queries the contract itself using
STATICCALL(EIP-214) and can cache the result (updateERC165Cache), with no automatic invalidation. - Managers:
setManagerhands registration rights to another address, useful for multisigs and EOAs.
Same address everywhere. The registry is deployed with "Nick's method": a pre-signed deployment transaction that does not use EIP-155 chain IDs and whose signature r and s are the repeating pattern 0x1820…, so nobody knows the deployer's key. Anyone can fund the one-time deployer and broadcast it on any EVM chain, always yielding 0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24.
Sample code
A contract registering itself as an ERC-777 recipient (the pattern ERC-777 tokens look for):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC1820Registry {
function setInterfaceImplementer(address account, bytes32 interfaceHash, address implementer) external;
function getInterfaceImplementer(address account, bytes32 interfaceHash) external view returns (address);
}
contract Receiver {
IERC1820Registry constant REGISTRY = IERC1820Registry(0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24);
bytes32 constant RECIPIENT_HASH = keccak256("ERC777TokensRecipient");
constructor() {
// implementer == address(this) == msg.sender, so no accept-magic check is needed
REGISTRY.setInterfaceImplementer(address(this), RECIPIENT_HASH, address(this));
}
function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external {
// handle incoming ERC-777 tokens
}
}
Things to know
- Status is Final. Use 1820, not 820; the spec states ERC-1820 must be used in place of ERC-820.
- The registry only exists on a chain if someone has broadcast the deployment transaction there. Check for code at the address before relying on it on a new network.
- The deployment transaction pays a fixed 100 gwei gas price and lacks replay protection, so it can only be broadcast on chains (and nodes) that accept pre-EIP-155 transactions.
- The ERC-165 cache is manual: if a contract's supported interfaces change, someone must call
updateERC165Cache. - New token designs mostly avoid registry-based hooks; ERC-777's reliance on 1820 callbacks has been linked to reentrancy issues in integrations.