ERC-6821 ENS name support for web3:// URLs (Support ENS Name for Web3 URL)
Draft · Names & metadata · created 2023-04-02
Defines a standard procedure for converting an ENS name used in a web3:// address (ERC-4804) into the actual smart contract address.
Why it is needed
ERC-4804 defines a way to call a smart contract directly using an address starting with web3://. There are two ways to reference the contract in this scheme: a long hexadecimal address starting with 0x, or a name registered with a name service. However, when a name is used, there was no standardized procedure for converting that name into the actual contract address, which meant different implementations could resolve addresses in different ways, producing different results even for the same name, and there was no way to indicate which chain the contract pointed to by the name was on. This standard defines, step by step, the procedure for converting Ethereum Name Service (ENS) names into contract addresses for ERC-4804, so that any implementation that follows it will resolve the same name to the same contract.
In depth
Relationship with ERC-4804
ERC-4804 defines a way to call smart contracts using a web3:// URI in RFC 2396 format. In the URI, a contract can be specified either as an address or as a name registered with a name service; when a name is used, a separate method is needed to resolve the contract address from that name. This standard defines that mapping for the case where the name is an ENS name. As stated in the requires section of the preamble, it presupposes ERC-137, ERC-634, ERC-3770, and ERC-4804.
The three-step address resolution procedure
Taking the contractName and chainid obtained from a web3:// URI as input, the protocol resolves the address in the following order. Step 1, look up the contentcontract text record from the ENS resolver on the chainid chain. If that chain has no ENS, or the record is not a valid ETH address, an error is returned. Step 2, if there is no contentcontract record, use the address obtained by resolving the name through ERC-137's contract address interface. Step 3, if the address obtained that way is the zero address, an "address not found" error is returned. In other words, the contentcontract record takes priority when it exists, and only falls back to ENS's general address resolution when it does not.
The contentcontract record and chain override
The contentcontract text record can hold a value in one of two forms: a hexadecimal Ethereum address prefixed with 0x, or an ERC-3770 chain-specific address. If the value is an ERC-3770 chain-specific address, the chainid used to call the message is overwritten with the chainid specified in that address instead of the value in the URI. This mechanism lets a single ENS name point to a contract on a different chain.
Why a text record is used instead of contenthash
ENS already has a record called contenthash intended for pointing to content, but this standard instead uses a contentcontract text record holding an ERC-3770 chain-specific address. This is because text records are in a human-readable form, which is also a design principle of ERC-4804. Using a text record also leaves room to add fields such as a TTL (time to live) in the future.
Security considerations and document status
The Security Considerations section of the original text states only that no security considerations have been identified. Meanwhile, this document is in Draft status. Since it is a proposal that has not yet been finalized, details such as the procedure or record name may change going forward.