---
eip: 1577
label: ERC-1577
title: contenthash field for ENS
status: Stagnant
type: Standards Track
category: ERC
created: 2018-11-13
official: https://eips.ethereum.org/EIPS/eip-1577
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1577.md
canonical: https://eips.huatuo.xyz/ja/eip-1577/
lang: ja
tldr: ENS リゾルバーに contenthash レコードを追加し、自己記述型の multicodec 形式を使って、名前が IPFS や Swarm などのネットワーク上のコンテンツを指せるようにする。
tags: [ens, ipfs, swarm, resolver, dweb]
---

# ERC-1577: contenthash field for ENS

> This EIP introduces the new contenthash field for ENS resolvers, allowing for a better defined system of mapping names to network and content addresses. Additionally the content and multihash fields are deprecated.

**TL;DR:** ENS リゾルバーに contenthash レコードを追加し、自己記述型の multicodec 形式を使って、名前が IPFS や Swarm などのネットワーク上のコンテンツを指せるようにする。

## 何を解決するのか

ウォレットやブラウザは、ENS 名を IPFS や Swarm のような分散型ストレージ上でホストされたウェブサイトに解決し始めました。従来のリゾルバーのフィールド（`content` と `multihash`）では、ハッシュがどのネットワークのものなのかが明確ではなかったため、アプリは推測するしかなく、名前の所有者も自分のコンテンツがどう読み込まれるか確信できませんでした。

ERC-1577 はこれらを、値自体にプロトコル識別子を含む 1 つのフィールド `contenthash` に置き換えます。

## 仕組み

- このフィールドをサポートするリゾルバーは、[ERC-165](/eip-165/) の `supportsInterface(0xbc1c58d1)` から `true` を返します。
- `contenthash(node)` は、[multicodec](https://github.com/multiformats/multicodec) 形式の生のバイト列を返します。

```text
<protoCode uvarint><value []byte>
```

- IPFS（`0xe3`）と Swarm（`0xe4`）では、値はベースプレフィックスのない CIDv1 です。

```text
<protoCode uvarint><cid-version><multicodec-content-type><multihash-content-address>
```

- クライアントは、まずプロトコルコードを読み、サポートしていれば一致するネットワークでアドレスを解決しなければなりません（MUST）。
- 古い `content` と `multihash` フィールドは非推奨です。仕様は、少なくとも 2019 年 3 月 31 日までの猶予期間を求めており、その間クライアントはそれらにフォールバックしていました。

仕様の IPFS の例を分解すると次のとおりです。

| バイト | 意味 |
| --- | --- |
| `e3 01` | IPFS の名前空間（`0xe3` を uvarint にしたもの） |
| `01` | CID バージョン 1 |
| `70` | コンテンツタイプ dag-pb |
| `12 20` | sha2-256、32 バイトのダイジェスト |
| `29f2…3f1f` | ハッシュ |

## サンプルコード

仕様の例です。

```text
IPFS  binary: 0xe3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f
      text:   ipfs://QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4

Swarm binary: 0xe40101fa011b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
      text:   bzz://d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
```

ethers v6 で名前のコンテンツハッシュを読み取る例です。一般的なプロトコルは URL にデコードされます。

```ts
import { JsonRpcProvider, Contract, namehash } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const resolver = await provider.getResolver("vitalik.eth");
console.log(await resolver?.getContentHash()); // e.g. "ipfs://..."

// Or call the resolver directly for the raw bytes
const r = new Contract(resolver!.address,
  ["function contenthash(bytes32 node) view returns (bytes)"], provider);
console.log(await r.contenthash(namehash("vitalik.eth")));
```

リゾルバーコントラクトの内部:

```solidity
function contenthash(bytes32 node) external view returns (bytes memory);
event ContenthashChanged(bytes32 indexed node, bytes hash);
```

## 知っておくべきこと

- EIP リポジトリ上のステータスは **Stagnant** ですが、`contenthash` は、ENS リゾルバーと、ENS 対応のゲートウェイやブラウザが、分散型ウェブサイトのために使うレコードです。
- 標準化されているのはエンコーディングだけです。クライアントが実際にコンテンツを取得できるかどうかは、そのプロトコルへの対応状況に依存します。
- 値のエンコードには、バイト列を手で組み立てるのではなく、ライブラリ（たとえば仕様がリンクしている `content-hash` パッケージ）を使ってください。
- 名前解決そのものは [ENS (EIP-137)](/eip-137/) が定義しており、テキストレコードは [EIP-634](/eip-634/) にあります。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1577
