ERC-205 Storing and Retrieving ABIs via ENS (ENS support for contract ABIs)
Stagnant · Names & metadata · created 2017-02-06
If a contract's ABI (its list of functions) is stored in its ENS name, looking up the name alone lets you immediately learn how to interact with that contract.
Why it is needed
Interacting with a contract requires the function list information called the ABI. Today, this ABI must be obtained separately from an external source such as GitHub or a website. For contracts that are used only once, or whose ABI changes after an upgrade, the burden of figuring out where to get the latest ABI each time grows larger. Since an ABI itself is not large, ranging from a few hundred bytes to at most a few kilobytes, storing it alongside the name lookup in ENS means the ABI can be found in the same step as finding the name.
What to implement
function ABI(bytes32 node, uint256 contentType) constant returns (uint256, bytes);: Given an ENS node and a bitfield indicating the desired encodings, this returns the ABI encoded in one of the supported formats along with its encoding ID. If no ABI exists or none of the requested formats are supported, it returns (0, "").
In depth
Four ABI Encodings
Each encoding is distinguished by a unique constant with a single bit set, allowing up to 256 encodings to be represented within one uint. ID 1 is plain JSON, the most common but bulky and hard to parse on chain. ID 2 is zlib compressed JSON, easy to restore off chain but impractical for on chain consumers. ID 4 is CBOR, a superset of JSON that is smaller and easier to parse in constrained environments like the EVM, and can shrink further when combined with the stringref extension. ID 8 points to an external URI where the ABI is stored, the smallest option but one that introduces an external dependency.
Resolver Interface and Interface ID
The new resolver interface is defined by a single function, ABI(bytes32 node, uint256 contentType), with interface ID 0x2203ab56. contentType is a bitwise OR of the encodings the caller can accept, and the resolver must return the ABI encoded in one of the requested formats.
Valid for both forward and reverse records
The abi resolver profile is valid for both forward records and reverse records. This lets a contract register a canonical ABI on the reverse record of its own address.
Handling a failed lookup
If the resolver has no ABI for that function, or supports none of the requested formats, it must return (0, "").
Lookup order: two step fallback
An implementation that wants to fetch an ABI based on an ENS name must first attempt an ABI lookup on the name itself. If no result is returned, it must attempt a reverse lookup on the Ethereum address that the name points to. Implementations should support as many ABI encoding formats as possible.
Why store it on chain
Storing the ABI on chain lets applications obtain it without additional dependencies such as Swarm or HTTP access. Since ABIs are generally small, this is a worthwhile tradeoff in many cases. The two step lookup also allows the same contract to expose a different ABI per name (for example, serving only a minimal ABI to some callers), and lets an ABI be specified even for contracts that do not define one themselves. The fallback to the reverse record also lets a contract designate its own official ABI, so that when multiple names point to the same contract, the ABI does not need to be stored redundantly.
Standard status
This proposal was written in 2017 and its current status is Stagnant, a proposal that may still change further or may remain stalled as is.