This standard defines a universal registry smart contract where any address (contract or regular account) can register which interface it supports and which smart contract is responsible for its implementation.
This standard attempts to define a registry where smart contracts and regular accounts can publish which functionalities they implement—either directly or through a proxy contract .
The rest of the world can query this registry to ask if a specific address implements a given interface and which smart contract handles its implementation.
Interfaces with zeroes (`0`) as the the last 28 bytes are considered [ERC165] interfaces, and this registry SHALL forward the call to the contract to see if it implements the interface.
There has been different approaches to define pseudo-introspection in Ethereum. The first is [ERC165] which has the limitation that it cannot be used by regular accounts. The second attempt is [ERC672] which uses reverseENS. Using reverseENS has two issues. First, it is unnecessarily complex, and second, ENS is still a centralized contract controlled by a multisig. This multisig, theoretically would be able to modify the system.
The string of `a`'s at the end of the transaction is the `s` of the signature. From this pattern, one can clearly deduce that it is a deterministic signature generated by a human.
This nice `s` value is a "random number" generated deterministically by a human.
3. We recover the sender of this transaction. Thus we obtain an account that can broadcast that transaction, but we also have the warranty that nobody knows the private key of that account.
This operation can be done in any chain, guaranteeing that the contract address is going to always be the same and nobody will be able to mess up that address with a different contract.
This account is generated by reverse engineering it from its signature for the transaction. This way no one knows the private key, but it is known that it is the valid signer of the deployment transaction.
The contract has the address above for every chain it is deployed to.
<details>
<summary>Raw metadata of <code>./contracts/ERC820Registry.sol</code></summary>
<pre><codeclass="language-json">{
"compiler": {
"version": "0.4.24+commit.e67f0147"
},
"language": "Solidity",
"output": {
"abi": [
{
"constant": false,
"inputs": [
{
"name": "_addr",
"type": "address"
},
{
"name": "_interfaceHash",
"type": "bytes32"
},
{
"name": "_implementer",
"type": "address"
}
],
"name": "setInterfaceImplementer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_addr",
"type": "address"
}
],
"name": "getManager",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_addr",
"type": "address"
},
{
"name": "_newManager",
"type": "address"
}
],
"name": "setManager",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_interfaceName",
"type": "string"
}
],
"name": "interfaceHash",
"outputs": [
{
"name": "",
"type": "bytes32"
}
],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_contract",
"type": "address"
},
{
"name": "_interfaceId",
"type": "bytes4"
}
],
"name": "updateERC165Cache",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_addr",
"type": "address"
},
{
"name": "_interfaceHash",
"type": "bytes32"
}
],
"name": "getInterfaceImplementer",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_contract",
"type": "address"
},
{
"name": "_interfaceId",
"type": "bytes4"
}
],
"name": "implementsERC165InterfaceNoCache",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_contract",
"type": "address"
},
{
"name": "_interfaceId",
"type": "bytes4"
}
],
"name": "implementsERC165Interface",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "addr",
"type": "address"
},
{
"indexed": true,
"name": "interfaceHash",
"type": "bytes32"
},
{
"indexed": true,
"name": "implementer",
"type": "address"
}
],
"name": "InterfaceImplementerSet",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "addr",
"type": "address"
},
{
"indexed": true,
"name": "newManager",
"type": "address"
}
],
"name": "ManagerChanged",
"type": "event"
}
],
"devdoc": {
"author": "Jordi Baylina and Jacques Dafflon",
"methods": {
"getInterfaceImplementer(address,bytes32)": {
"params": {
"_addr": "Address being queried for the implementer of an interface. (If `_addr == 0` then `msg.sender` is assumed.)",
"_interfaceHash": "keccak256 hash of the name of the interface as a string. E.g., `web3.utils.keccak256('ERC777Token')`."
},
"return": "The address of the contract which implements the interface `_interfaceHash` for `_addr` or `0x0` if `_addr` did not register an implementer for this interface."
},
"getManager(address)": {
"params": {
"_addr": "Address for which to return the manager."
},
"return": "Address of the manager for a given address."
},
"implementsERC165Interface(address,bytes4)": {
"details": "This function may modify the state when updating the cache. However, this function must have the `view` modifier since `getInterfaceImplementer` also calls it. If called from within a transaction, the ERC165 cache is updated.",
"params": {
"_contract": "Address of the contract to check.",
"_interfaceId": "ERC165 interface to check."
},
"return": "`true` if `_contract` implements `_interfaceId`, false otherwise."
"_addr": "Address to define the interface for. (If `_addr == 0` then `msg.sender` is assumed.)",
"_interfaceHash": "keccak256 hash of the name of the interface as a string. For example, `web3.utils.keccak256('ERC777TokensRecipient')` for the `ERC777TokensRecipient` interface."
}
},
"setManager(address,address)": {
"params": {
"_addr": "Address for which to set the new manager. (If `_addr == 0` then `msg.sender` is assumed.)",
"_newManager": "Address of the new manager for `addr`. (Pass `0x0` to reset the manager to `_addr` itself.)"
}
},
"updateERC165Cache(address,bytes4)": {
"params": {
"_contract": "Address of the contract for which to update the cache.",
"_interfaceId": "ERC165 interface for which to update the cache."
"notice": "Query if an address implements an interface and through which contract."
},
"getManager(address)": {
"notice": "Get the manager of an address."
},
"implementsERC165Interface(address,bytes4)": {
"notice": "Checks whether a contract implements an ERC165 interface or not. The result is cached. If the cache is out of date, it must be updated by calling `updateERC165Cache`."
"notice": "Sets the contract which implements a specific interface for an address. Only the manager defined for that address can set it. (Each address is the manager for itself until it sets a new manager.)"
},
"setManager(address,address)": {
"notice": "Sets the `_newManager` as manager for the `_addr` address. The new manager will be able to call `setInterfaceImplementer` for `_addr`."
},
"updateERC165Cache(address,bytes4)": {
"notice": "Updates the cache with whether contract implements an ERC165 interface or not."
"content": "pragma solidity 0.4.24;\n// IV is a simply value to have a \"nice\" address for the registry, starting with `0x820`.\n// IV: 12302\n\n/// @dev The interface a contract MUST implement if it is the implementer of\n/// some interface for any address other than itself.\ninterface ERC820ImplementerInterface {\n /// @notice Indicates whether the contract implements the interface `interfaceHash` for the address `addr` or not.\n /// @param addr Address for which the contract will implement the interface\n /// @param interfaceHash keccak256 hash of the name of the interface\n /// @return ERC820_ACCEPT_MAGIC only if the contract implements `ìnterfaceHash` for the address `addr`.\n function canImplementInterfaceForAddress(address addr, bytes32 interfaceHash) public view returns(bytes32);\n}\n\n/// @title ERC820 Pseudo-introspection Registry Contract\n/// @author Jordi Baylina and Jacques Dafflon\n/// @notice This contract is the official implementation of the ERC820 Registry.\n/// @notice For more details, see https://eips.ethereum.org/EIPS/eip-820\ncontract ERC820Registry {\n /// @notice ERC165 Invalid ID.\n bytes4 constant INVALID_ID = 0xffffffff;\n /// @notice Method ID for the ERC165 supportsInterface method (= `bytes4(keccak256('supportsInterface(bytes4)'))`).\n bytes4 constant ERC165ID = 0x01ffc9a7;\n /// @notice Magic value which is returned if a contrct implements an interface on behalf of some other address.\n bytes32 constant ERC820_ACCEPT_MAGIC = keccak256(abi.encodePacked(\"ERC820_ACCEPT_MAGIC\"));\n\n mapping (address => mapping(bytes32 => address)) interfaces;\n mapping (address => address) managers;\n mapping (address => mapping(bytes4 => bool)) erc165Cached;\n\n /// @notice Indicates a contract is the `implementer` of `interfaceHash` for `addr`.\n event InterfaceImplementerSet(address indexed addr, bytes32 indexed interfaceHash, address indexed implementer);\n /// @notice Indicates `newManager` is the address of the new manager for `addr`.\n event ManagerChanged(address indexed addr, address indexed newManager);\n\n /// @notice Query if an address implements an interface and through which contract.\n /// @param _addr Address being queried for the implementer of an interface.\n /// (If `_addr == 0` then `msg.sender` is assumed.)\n /// @param _interfaceHash keccak256 hash of the name of the interface as a string.\n /// E.g., `web3.utils.keccak256('ERC777Token')`.\n /// @return The address of the contract which implements the interface `_interfaceHash` for `_addr`\n /// or `0x0` if `_addr` did not register an implementer for this interface.\n function getInterfaceImplementer(address _addr, bytes32 _interfaceHash) external view returns (address) {\n address addr = _addr == 0 ? msg.sender : _addr;\n if (isERC165Interface(_interfaceHash)) {\n bytes4 erc165InterfaceHash = bytes4(_interfaceHash);\n return implementsERC165Interface(addr, erc165InterfaceHash) ? addr : 0;\n }\n return interfaces[addr][_interfaceHash];\n }\n\n /// @notice Sets the contract which implements a specific interface for an address.\n /// Only the manager defined for that address can set it.\n /// (Each address is the manager for itself until it sets a new manager.)\n /// @param _addr Address to define the interface for. (If `_addr == 0` then `msg.sender` is assumed.)\n /// @param _interfaceHash keccak256 hash of the name of the interface as a string.\n /// For example, `web3.utils.keccak256('ERC777TokensRecipient')` for the `ERC777TokensRecipient` interface.\n function setInterfaceImplementer(address _addr, bytes32 _interfaceHash, address _implementer) external {\n address addr = _addr == 0 ? msg.sender : _addr;\n require(getManager(addr) == msg.sender, \"Not the manager\");\n\n require(!isERC165Interface(_interfaceHash), \"Must not be a ERC165 hash\");\n if (_implementer != 0 && _implementer != msg.sender) {\n require(\n ERC820
If the interface is part of a standard, it is best practice to explicitly state the interface name and link to this published [ERC820] such that other people don't have to come here to look up these rules.
If the interface is part of an approved ERC, it MUST be named `ERC###XXXXX` where `###` is the number of the ERC and XXXXX should be the name of the interface in CamelCase. The meaning of this interface SHOULD be defined in the specified ERC.
Any interface where the last 28 bytes are zeroes (`0`) SHALL be considered an [ERC165] interface.
#### **Private User-defined Interfaces**
This scheme is extensible. You MAY make up your own interface name and raise awareness to get other people to implement it and then check for those implementations. Have fun but please, you MUST not conflict with the reserved designations above.
### Set An Interface For An Address
For any address to set a contract as the interface implementation, it must call the following function of the [ERC820] registry:
``` solidity
function setInterfaceImplementer(address _addr, bytes32 _interfaceHash, address _implementer) public
```
Sets the contract that will handle a specific interface.
Only a `manager` defined for that address can set it. (Each address is the manager for itself until a new manager is defined)
*NOTE*: If `_addr` and `_implementer` are two different addresses, then:
- The `_implementer` MUST implement the `ERC820ImplementerInterface` (detailed below).
- Calling `canImplementInterfaceForAddress` on `_implementer` with the given `_addr` and `_interfaceHash` MUST return the `ERC820_ACCEPT_MAGIC` value.
*NOTE*: The `_interfaceHash` MUST NOT be an [ERC165] interface—it MUST NOT end with 28 zeroes (`0`).
> <small>**parameters**</small>
> <small>`_addr` Address to define the interface for (if `_addr == 0` them `msg.sender` is assumed)</small>
> <small>`_interfaceHash` `keccak256` hash of the name of the interface as a string, for example `web3.utils.keccak256('ERC777TokensRecipient')` for the ERC777TokensRecipient interface.</small>
### Get An Implementation Of An Interface For An Address
Anyone MAY query the [ERC820] Registry to obtain the address of a contract implementing an interface on behalf of some address using the `getInterfaceImplementer` function.
``` solidity
function getInterfaceImplementer(address _addr, bytes32 _interfaceHash) public view returns (address)
```
Query if an address implements an interface and through which contract.
*NOTE*: If the last 28 bytes of the `_interfaceHash` are zeroes (`0`), then the first 4 bytes are considered an [ERC165] interface and the registry SHALL forward the call to the contract at `_addr` to see if it implements the [ERC165] interface (the first 4 bytes of `_interfaceHash`). The registry SHALL also cache [ERC165] queries in order to reduce gas consumption. Anyone MAY call the `erc165UpdateCache` function to update whether a contract implements an interface or not.
> <small>**parameters**</small>
> <small>`_addr` Address being queried for the implementer of an interface. (If `_addr == 0` them `msg.sender` is assumed.)</small>
> <small>`_interfaceHash` keccak256 hash of the name of the interface as a string. E.g. `web3.utils.keccak256('ERC777Token')`</small>
> <small>**returns:** The address of the contract which implements the interface `_interfaceHash` for `_addr` or `0x0` if `_addr` did not registeran implemeter for this interface.</small>
/// @notice Indicates whether the contract implements the interface `interfaceHash` for the address `addr`.
/// @param addr Address for which the contract will implement the interface
/// @param interfaceHash keccak256 hash of the name of the interface
/// @return ERC820_ACCEPT_MAGIC only if the contract implements `ìnterfaceHash` for the address `addr`.
function canImplementInterfaceForAddress(address addr, bytes32 interfaceHash) public view returns(bytes32);
}
```
Any contract being registered as the implementation of an interface for a given address MUST implement said interface. In addition if it implements an interface on behalf of a different address, the contract MUST implement the `ERC820ImplementerInterface` shown above.
``` solidity
function canImplementInterfaceForAddress(address addr, bytes32 interfaceHash) view public returns(bytes32);
```
Indicates whether a contract implements an interface (`interfaceHash`) for a given address (`addr`).
If a contract implements the interface (`interfaceHash`) for a given address (`addr`), it MUST return `ERC820_ACCEPT_MAGIC` when called with the `addr` and the `interfaceHash`. If it does not implement the `interfaceHash` for a given address (`addr`), it MUST NOT return `ERC820_ACCEPT_MAGIC`.
> <small>**parameters**</small>
> <small>`addr`: Address for which the interface is implemented</small>
> <small>`interfaceHash`: Hash of the interface which is implemented</small>
The special value `ERC820_ACCEPT_MAGIC` is defined as the `keccka256` hash of the string `"ERC820_ACCEPT_MAGIC"`.
> The reason to return `ERC820_ACCEPT_MAGIC` instead of a boolean is to prevent cases where a contract fails to implement the `canImplementInterfaceForAddress` but implements a fallback function which does not throw. In this case, since `canImplementInterfaceForAddress` does not exist, the fallback function is called instead, executed without throwing and returns `1`. Thus making it appear as if `canImplementInterfaceForAddress` returned `true`.
### Manager
The manager of an address (regular account or a contract) is the only entity allowed to register implementations of interfaces for the address. By default any address is its own manager.
The manager can transfer its role to another address by calling `setManager` with the address for which to transfer the manager and the address of the new manager.
``` solidity
function setManager(address _addr, address _newManager) public