EIPs Explained

ERC-1062 · Stagnant · ERC · 2018-05-02

ERC-1062: Formalize IPFS hash into ENS(Ethereum Name Service) resolver

An early proposal for storing IPFS content hashes in an ENS resolver, so a human-readable name like mysite.eth could point to a decentralized website.

What problem does it solve?

IPFS addresses content by its hash, a long Base58 string such as QmXo.... That is great for integrity but useless for humans: nobody remembers or types it. ENS (EIP-137) already maps readable names like mysite.eth to data stored in a resolver contract.

ERC-1062 proposed a standard way to put an IPFS hash into an ENS resolver and get it back out, so a browser or extension could type an .eth name and load a fully decentralized site. The goal was a simple bridge between human-readable names and content-addressed storage.

How it works

The main difficulty is encoding. IPFS shows hashes as Base58 strings, while Ethereum contracts and JSON-RPC deal in raw bytes shown as hex. The proposal bridges the two through the underlying binary multihash:

  1. Store: decode the Base58 IPFS hash into bytes, then write those bytes to the resolver.
  2. Read: read the bytes from the resolver and encode them back into Base58 to get the IPFS hash.

It relies on two resolver methods:

Function Purpose
setMultihash(bytes32 node, bytes hash) Owner of the ENS name stores the multihash bytes
multihash(bytes32 node) Anyone reads the stored bytes back

node is the usual ENS namehash of the name. Only the owner of that node may call the setter.

A classic IPFS (CIDv0) hash decodes to bytes starting with 0x12 0x20: 0x12 means SHA-256 and 0x20 means a 32-byte digest, followed by the digest itself.

Sample code

Converting between Base58 and hex with ethers v6 (the spec's own examples use the multihashes npm library):

import { decodeBase58, encodeBase58, getBytes, toBeHex } from "ethers";

// IPFS Base58 hash -> 0x-hex bytes for the resolver
export const toHex = (ipfsHash: string): string => toBeHex(decodeBase58(ipfsHash));

// 0x-hex bytes from the resolver -> IPFS Base58 hash
export const toBase58 = (hex: string): string => encodeBase58(getBytes(hex));

The resolver interface as described:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IMultihashResolver {
    function setMultihash(bytes32 node, bytes calldata hash) external; // only node owner
    function multihash(bytes32 node) external view returns (bytes memory);
}

Things to know

  • Status: Stagnant. This proposal was never finalized.
  • The ecosystem standardized on the contenthash resolver field from EIP-1577 instead. It can hold IPFS, Swarm and other content identifiers with a self-describing prefix, and is what ENS-aware wallets, gateways and libraries read today (for example ethers' resolver.getContentHash()).
  • multihash stores only the hash, without saying which storage network it belongs to. That limitation is one reason a more general field was preferred.
  • If you are publishing a site behind an ENS name today, set contenthash, not multihash.

#ens #ipfs #resolver #storage #naming

Details

Authors
Phyrex Tsai <[email protected]>, Portal Network Team
Status
Stagnant
Type
Standards Track / ERC
Created
2018-05-02
Required by

Machine-readable: Markdown · JSON