{"eip":2157,"title":"dType Storage Extension - Decentralized Type System for EVM","description":"This ERC is an extension of ERC-1900, proposing an optional storage extension for dType, a decentralized type system, specifying a general ABI for all storage contracts that contain type instances.","authors":["Loredana Cirstea (@loredanacirstea)","Christian Tzurcanu (@ctzurcanu)"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2019-06-28","requires":[1900],"discussionsTo":"https://github.com/ethereum/EIPs/issues/2157","repo":"ERCs","label":"ERC-2157","officialUrl":"https://eips.ethereum.org/EIPS/eip-2157","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2157.md","url":"https://eips.huatuo.xyz/eip-2157/","tldr":{"en":"An optional extension to the dType type registry (ERC-1900) that standardises how each type's instances are stored on-chain, so anyone can find and read public data for a type at a predictable location.","ja":"dType 型レジストリ（ERC-1900）のオプション拡張。各型のインスタンスをオンチェーンにどう保存するかを標準化し、誰でも予測可能な場所で型の公開データを見つけて読めるようにする。","ko":"dType 타입 레지스트리(ERC-1900)의 선택적 확장으로, 각 타입의 인스턴스를 온체인에 저장하는 방식을 표준화해 누구나 예측 가능한 위치에서 타입의 공개 데이터를 찾아 읽을 수 있게 한다.","zh":"dType 类型注册表（ERC-1900）的可选扩展，规范了每种类型的实例如何存储在链上，让任何人都能在可预测的位置找到并读取某个类型的公开数据。"},"tags":["dtype","types","storage","data","erc"],"explainers":{"en":{"lang":"en","tldr":"An optional extension to the dType type registry (ERC-1900) that standardises how each type's instances are stored on-chain, so anyone can find and read public data for a type at a predictable location.","tags":["dtype","types","storage","data","erc"],"related":[1900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2157/","markdown":"## What problem does it solve?\n\n[ERC-1900](/eip-1900/) (dType) is an on-chain registry of data types, such as a \"Product\" struct defined in a Solidity library, so that projects can share type definitions. It says nothing about **where the actual records of a type live**. Finding all public data of a type means scanning the chain or relying on block explorers and other centralised caches.\n\nERC-2157 standardises that last step. Every registered type points to one storage contract with a common CRUD interface, so any app or contract can locate and read the public records of a type deterministically.\n\n## How it works\n\nTwo contracts are added for each type:\n\n**`TypeRootContract`**: the `contractAddress` field in the type's dType metadata now points here instead of straight to the type library. It holds two addresses:\n\n- `libraryAddress`: the ERC-1900 library defining the type,\n- `storageAddress`: the contract holding instances of the type.\n\n**`TypeStorageContract`**: stores type instances as records, each addressed by a primary identifier computed by the type library's `getIdentifier` function, and by an increasing index. The standard interface:\n\n| Function | Purpose |\n| --- | --- |\n| `insert(data)` / `insertBytes(bytes)` | Add a record; returns its identifier |\n| `update(identifier, data)` | Replace a record |\n| `remove(identifier)` | Delete a record |\n| `isStored(identifier)` | Existence check |\n| `getByHash(identifier)` / `getByIndex(index)` | Read a record |\n| `count()` | Number of records |\n\n`LogNew`, `LogUpdate` and `LogRemove` events track changes. A common interface plus the dType registry is enough to reconstruct a storage contract's ABI. Separating type definitions, logic and data is meant to encourage a functional style of composition.\n\n## Sample code\n\nResolving where a type's data lives and reading a record (ethers v6). The dType registry lookup itself is defined by ERC-1900 and is omitted here:\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\n// contractAddress taken from the type's ERC-1900 metadata\nconst root = new Contract(\n  process.env.TYPE_ROOT!,\n  [\"function storageAddress() view returns (address)\", \"function libraryAddress() view returns (address)\"],\n  provider,\n);\n\nconst storage = new Contract(\n  await root.storageAddress(),\n  [\n    \"function count() view returns (uint256)\",\n    \"function typeIndex(uint256) view returns (bytes32)\",\n    \"function isStored(bytes32) view returns (bool)\",\n  ],\n  provider,\n);\n\nconst n: bigint = await storage.count();\nfor (let i = 0n; i \u003c n; i++) {\n  const id = await storage.typeIndex(i); // public array getter from the stub\n  console.log(i, id, await storage.isStored(id));\n}\n```\n\nRecords come back as the type's struct. Build the full ABI from the type definition in the dType registry to decode `getByHash`.\n\n## Things to know\n\n- Status is **Stagnant**, as is ERC-1900, which it depends on.\n- The spec relies on the then-experimental ABIEncoderV2 to pass structs, which is now the default in Solidity 0.8.\n- Access control and mutability rules are explicitly out of scope. The storage stub includes no permission checks, so real deployments must add their own.\n- The spec promises test cases and a final implementation \"when consensus is reached\"; neither was added.\n"},"ja":{"lang":"ja","tldr":"dType 型レジストリ（ERC-1900）のオプション拡張。各型のインスタンスをオンチェーンにどう保存するかを標準化し、誰でも予測可能な場所で型の公開データを見つけて読めるようにする。","tags":["dtype","types","storage","data","erc"],"related":[1900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2157/","markdown":"## 何を解決するのか\n\n[ERC-1900](/eip-1900/)（dType）は、Solidity ライブラリで定義された「Product」構造体のようなデータ型のオンチェーンレジストリで、プロジェクト間で型定義を共有できるようにするものです。ただし、**ある型の実際のレコードがどこに置かれるか**については何も定めていません。ある型の公開データをすべて見つけるには、チェーンをスキャンするか、ブロックエクスプローラーなどの中央集権的なキャッシュに頼るしかありません。\n\nERC-2157 はこの最後のステップを標準化します。登録された各型が、共通の CRUD インターフェースを持つ 1 つのストレージコントラクトを指すため、どのアプリやコントラクトも、型の公開レコードの場所を決定的に特定して読み取れます。\n\n## 仕組み\n\n型ごとに 2 つのコントラクトを追加します。\n\n**`TypeRootContract`**：型の dType メタデータにある `contractAddress` フィールドは、型ライブラリを直接指す代わりに、このコントラクトを指すようになります。次の 2 つのアドレスを保持します。\n\n- `libraryAddress`：その型を定義する ERC-1900 のライブラリ\n- `storageAddress`：その型のインスタンスを保持するコントラクト\n\n**`TypeStorageContract`**：型のインスタンスをレコードとして保存します。各レコードは、型ライブラリの `getIdentifier` 関数で計算される主識別子と、増加するインデックスでアドレス指定されます。標準インターフェースは次のとおりです。\n\n| 関数 | 役割 |\n| --- | --- |\n| `insert(data)` / `insertBytes(bytes)` | レコードを追加し、その識別子を返す |\n| `update(identifier, data)` | レコードを置き換える |\n| `remove(identifier)` | レコードを削除する |\n| `isStored(identifier)` | 存在確認 |\n| `getByHash(identifier)` / `getByIndex(index)` | レコードを読み取る |\n| `count()` | レコード数 |\n\n`LogNew`、`LogUpdate`、`LogRemove` の各イベントが変更を追跡します。共通インターフェースと dType レジストリがあれば、ストレージコントラクトの ABI を再構築できます。型定義、ロジック、データを分離することで、関数型スタイルの合成を促すことを意図しています。\n\n## サンプルコード\n\n型のデータの置き場所を解決し、レコードを読み取る例です（ethers v6）。dType レジストリの検索自体は ERC-1900 で定義されているため、ここでは省略しています。\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\n// contractAddress taken from the type's ERC-1900 metadata\nconst root = new Contract(\n  process.env.TYPE_ROOT!,\n  [\"function storageAddress() view returns (address)\", \"function libraryAddress() view returns (address)\"],\n  provider,\n);\n\nconst storage = new Contract(\n  await root.storageAddress(),\n  [\n    \"function count() view returns (uint256)\",\n    \"function typeIndex(uint256) view returns (bytes32)\",\n    \"function isStored(bytes32) view returns (bool)\",\n  ],\n  provider,\n);\n\nconst n: bigint = await storage.count();\nfor (let i = 0n; i \u003c n; i++) {\n  const id = await storage.typeIndex(i); // public array getter from the stub\n  console.log(i, id, await storage.isStored(id));\n}\n```\n\nレコードは型の構造体として返ります。`getByHash` をデコードするには、dType レジストリの型定義から完全な ABI を組み立ててください。\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。依存先の ERC-1900 も同様です。\n- この仕様は、構造体を渡すために、当時実験的だった ABIEncoderV2 に依存しています。これは現在、Solidity 0.8 ではデフォルトです。\n- アクセス制御と可変性のルールは明示的に対象外です。ストレージのスタブには権限チェックが含まれないため、実際のデプロイでは各自で追加する必要があります。\n- 仕様は「コンセンサスが得られたとき」にテストケースと最終実装を提供すると約束していますが、どちらも追加されませんでした。\n"},"ko":{"lang":"ko","tldr":"dType 타입 레지스트리(ERC-1900)의 선택적 확장으로, 각 타입의 인스턴스를 온체인에 저장하는 방식을 표준화해 누구나 예측 가능한 위치에서 타입의 공개 데이터를 찾아 읽을 수 있게 한다.","tags":["dtype","types","storage","data","erc"],"related":[1900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2157/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-1900](/eip-1900/)(dType)은 Solidity 라이브러리에 정의된 \"Product\" 구조체 같은 데이터 타입의 온체인 레지스트리로, 프로젝트들이 타입 정의를 공유할 수 있게 해 줍니다. 하지만 **한 타입의 실제 레코드가 어디에 있는지**는 정하지 않습니다. 어떤 타입의 공개 데이터를 모두 찾으려면 체인을 스캔하거나 블록 익스플로러 같은 중앙화된 캐시에 의존해야 합니다.\n\nERC-2157은 이 마지막 단계를 표준화합니다. 등록된 모든 타입이 공통 CRUD 인터페이스를 가진 스토리지 컨트랙트 하나를 가리키므로, 어떤 앱이나 컨트랙트든 타입의 공개 레코드 위치를 결정적으로 찾아 읽을 수 있습니다.\n\n## 어떻게 동작하나요?\n\n타입마다 컨트랙트 두 개가 추가됩니다.\n\n**`TypeRootContract`**: 타입의 dType 메타데이터에 있는 `contractAddress` 필드가 이제 타입 라이브러리 대신 이 컨트랙트를 가리킵니다. 두 개의 주소를 보관합니다.\n\n- `libraryAddress`: 타입을 정의하는 ERC-1900 라이브러리\n- `storageAddress`: 타입의 인스턴스를 보관하는 컨트랙트\n\n**`TypeStorageContract`**: 타입 인스턴스를 레코드로 저장하며, 각 레코드는 타입 라이브러리의 `getIdentifier` 함수가 계산한 기본 식별자와 증가하는 인덱스로 주소가 지정됩니다. 표준 인터페이스는 다음과 같습니다.\n\n| 함수 | 역할 |\n| --- | --- |\n| `insert(data)` / `insertBytes(bytes)` | 레코드를 추가하고 식별자를 반환 |\n| `update(identifier, data)` | 레코드를 교체 |\n| `remove(identifier)` | 레코드를 삭제 |\n| `isStored(identifier)` | 존재 여부 확인 |\n| `getByHash(identifier)` / `getByIndex(index)` | 레코드를 읽기 |\n| `count()` | 레코드 수 |\n\n`LogNew`, `LogUpdate`, `LogRemove` 이벤트가 변경 사항을 추적합니다. 공통 인터페이스와 dType 레지스트리만 있으면 스토리지 컨트랙트의 ABI를 재구성할 수 있습니다. 타입 정의, 로직, 데이터를 분리한 것은 함수형 스타일의 조합을 장려하려는 의도입니다.\n\n## 샘플 코드\n\n타입의 데이터가 있는 위치를 찾아 레코드를 읽는 예시입니다(ethers v6). dType 레지스트리 조회 자체는 ERC-1900에서 정의하므로 여기서는 생략했습니다.\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\n// contractAddress taken from the type's ERC-1900 metadata\nconst root = new Contract(\n  process.env.TYPE_ROOT!,\n  [\"function storageAddress() view returns (address)\", \"function libraryAddress() view returns (address)\"],\n  provider,\n);\n\nconst storage = new Contract(\n  await root.storageAddress(),\n  [\n    \"function count() view returns (uint256)\",\n    \"function typeIndex(uint256) view returns (bytes32)\",\n    \"function isStored(bytes32) view returns (bool)\",\n  ],\n  provider,\n);\n\nconst n: bigint = await storage.count();\nfor (let i = 0n; i \u003c n; i++) {\n  const id = await storage.typeIndex(i); // public array getter from the stub\n  console.log(i, id, await storage.isStored(id));\n}\n```\n\n레코드는 해당 타입의 구조체로 반환됩니다. `getByHash`를 디코딩하려면 dType 레지스트리의 타입 정의로 전체 ABI를 구성하세요.\n\n## 알아둘 점\n\n- 상태는 **Stagnant**이며, 의존하는 ERC-1900도 마찬가지입니다.\n- 명세는 구조체를 전달하기 위해 당시 실험적이던 ABIEncoderV2에 의존하는데, 이는 이제 Solidity 0.8의 기본값입니다.\n- 접근 제어와 가변성 규칙은 명시적으로 범위 밖입니다. 스토리지 스텁에는 권한 검사가 없으므로, 실제 배포에서는 직접 추가해야 합니다.\n- 명세는 \"합의에 도달하면\" 테스트 케이스와 최종 구현을 제공하겠다고 약속했지만, 둘 다 추가되지 않았습니다.\n"},"zh":{"lang":"zh","tldr":"dType 类型注册表（ERC-1900）的可选扩展，规范了每种类型的实例如何存储在链上，让任何人都能在可预测的位置找到并读取某个类型的公开数据。","tags":["dtype","types","storage","data","erc"],"related":[1900],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2157/","markdown":"## 它解决什么问题？\n\n[ERC-1900](/eip-1900/)（dType）是一个链上数据类型注册表，例如在 Solidity 库中定义的\"Product\"结构体，让各项目可以共享类型定义。但它没有说明**某个类型的实际记录存放在哪里**。要找到某个类型的所有公开数据，就得扫描整条链，或者依赖区块浏览器等中心化缓存。\n\nERC-2157 规范了最后这一步。每个已注册的类型都指向一个带有通用 CRUD 接口的存储合约，这样任何应用或合约都能确定性地定位并读取某个类型的公开记录。\n\n## 它如何运作\n\n每个类型会新增两个合约：\n\n**`TypeRootContract`**：类型的 dType 元数据中的 `contractAddress` 字段现在指向它，而不是直接指向类型库。它保存两个地址：\n\n- `libraryAddress`：定义该类型的 ERC-1900 库，\n- `storageAddress`：保存该类型实例的合约。\n\n**`TypeStorageContract`**：把类型实例存储为记录，每条记录通过由类型库的 `getIdentifier` 函数计算出的主标识符和一个递增的索引来寻址。标准接口如下：\n\n| 函数 | 用途 |\n| --- | --- |\n| `insert(data)` / `insertBytes(bytes)` | 添加记录；返回其标识符 |\n| `update(identifier, data)` | 替换记录 |\n| `remove(identifier)` | 删除记录 |\n| `isStored(identifier)` | 检查是否存在 |\n| `getByHash(identifier)` / `getByIndex(index)` | 读取记录 |\n| `count()` | 记录数量 |\n\n`LogNew`、`LogUpdate` 和 `LogRemove` 事件用于跟踪变更。通用接口加上 dType 注册表，就足以重建存储合约的 ABI。把类型定义、逻辑和数据分离，旨在鼓励函数式的组合风格。\n\n## 示例代码\n\n解析某个类型的数据存放位置并读取一条记录（ethers v6）。dType 注册表本身的查询由 ERC-1900 定义，这里省略：\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\n\n// contractAddress taken from the type's ERC-1900 metadata\nconst root = new Contract(\n  process.env.TYPE_ROOT!,\n  [\"function storageAddress() view returns (address)\", \"function libraryAddress() view returns (address)\"],\n  provider,\n);\n\nconst storage = new Contract(\n  await root.storageAddress(),\n  [\n    \"function count() view returns (uint256)\",\n    \"function typeIndex(uint256) view returns (bytes32)\",\n    \"function isStored(bytes32) view returns (bool)\",\n  ],\n  provider,\n);\n\nconst n: bigint = await storage.count();\nfor (let i = 0n; i \u003c n; i++) {\n  const id = await storage.typeIndex(i); // public array getter from the stub\n  console.log(i, id, await storage.isStored(id));\n}\n```\n\n记录会以该类型的结构体形式返回。请根据 dType 注册表中的类型定义构建完整的 ABI，以解码 `getByHash`。\n\n## 需要注意\n\n- 状态为 **Stagnant**，它所依赖的 ERC-1900 也是如此。\n- 规范依赖当时仍属实验性的 ABIEncoderV2 来传递结构体，该功能现在已是 Solidity 0.8 的默认设置。\n- 访问控制和可变性规则被明确排除在范围之外。存储合约的桩代码不包含任何权限检查，因此实际部署必须自行添加。\n- 规范承诺会在\"达成共识时\"提供测试用例和最终实现，但两者都没有补上。\n"}},"requiredBy":[2193]}
