Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
ERC-2157 proposes separating type definitions from data storage on Ethereum to facilitate data sharing across applications.
This article translates, summarizes, and expands on the following proposal.
More EIP explainers:
Overview
ERC-2157 proposes a storage extension for dType, a decentralized type system.
It extends ERC-1900 by defining a common application binary interface (ABI) for storage contracts that hold instances of registered types. Applications can use consistent operations to retrieve data from these contracts, facilitating the use of typed data both on-chain and off-chain.
For ERC-1900, see the following article.
ERC-1900: Understanding the decentralized type system for EVM contracts
The standardized interface is intended to simplify the development of applications, such as decentralized marketplaces, that depend on publicly accessible datasets organized around shared types.
Motivation
Ethereum provides several mechanisms for addressing contract state, but there is no universal application-level convention for discovering and addressing arbitrary typed records across contracts.
This is less problematic for data intended to be consumed by a particular application. Public datasets intended for reuse across applications, however, benefit from a common discovery and retrieval mechanism. Restricting a contract's interface does not make its underlying on-chain state confidential.
ERC-1900 provides a foundation for interoperability by standardizing type definitions. A broader shared data ecosystem also requires predictable ways to locate and retrieve instances of those types.
For example, if marketplace records follow a common type and storage interface, applications can discover and retrieve product information without depending exclusively on a centralized cache.
Standardized interfaces and information from the dType registry can also help tools reconstruct the applicable ABI. This is distinct from automatically recovering an arbitrary contract's full ABI from bytecode alone.
Future extensions could introduce access-control policies governing changes to shared datasets. Common type definitions and storage conventions could also help applications exchange data across networks, although actual cross-chain communication and verification require separate mechanisms.
Separating data definitions from storage and behavior can facilitate functional programming patterns in Solidity and other contract languages.
Specification
TypeRootContract
In ERC-1900, the contractAddress field in a type's metadata identifies the contract associated with its type definition.
ERC-2157 uses this field to reference a TypeRootContract. The root contract records both the type library (libraryAddress) and the storage contract holding instances of the type (storageAddress).
This links the type definition with the location of its instance data.
contract TypeRootContract {
address public libraryAddress;
address public storageAddress;
constructor(address _library, address _storage) public {
libraryAddress = _library;
storageAddress = _storage;
}
}The two addresses identify:
libraryAddress- The Ethereum address of the type library defined under ERC-1900.
storageAddress- The Ethereum address of the TypeStorageContract holding instances of that type.
TypeStorageContract
import './TypeALib.sol';
contract TypeAStorage {
using TypeALib for TypeALib.TypeA;
bytes32[] public typeIndex;
mapping(bytes32 => Type) public typeStruct;
struct Type {
TypeALib.TypeA data;
uint256 index;
}
event LogNew(bytes32 indexed identifier, uint256 indexed index);
event LogUpdate(bytes32 indexed identifier, uint256 indexed index);
event LogRemove(bytes32 indexed identifier, uint256 indexed index);
function insert(TypeALib.TypeA memory data) public returns (bytes32 identifier);
function insertBytes(bytes memory data) public returns (bytes32 identifier);
function remove(bytes32 identifier) public returns(uint256 index);
function update(bytes32 identifier, TypeALib.TypeA memory data) public returns(bytes32 identifier)
function isStored(bytes32 identifier) public view returns(bool stored);
function getByHash(bytes32 identifier) public view returns(TypeALib.TypeA memory data);
function getByIndex(uint256 index) public view returns(TypeALib.TypeA memory data);
function count() public view returns(uint256 counter);
}A TypeStorageContract stores instances of a particular type and exposes standardized operations for retrieving and managing those instances.
Each record is addressable through a primary identifier derived using the type library's getIdentifier function.
The proposal follows the create, read, update, and delete (CRUD) pattern. Each stored record also has an index that supports enumeration. The stability and ordering of these indices depend on the storage implementation, particularly when records are removed.
Events and structs
Type
struct Type {
TypeALib.TypeA data;
uint256 index;
}Represents a stored instance of TypeA together with its index.
Fields
data- The typed record defined by TypeALib.
index- The index associated with the record in the storage collection.
LogNew
event LogNew(bytes32 indexed identifier, uint256 indexed index);Emitted when a new record is inserted.
Parameters
identifier- The identifier of the new record.
index- Its associated index.
LogUpdate
event LogUpdate(bytes32 indexed identifier, uint256 indexed index);Emitted when an existing record is updated.
Parameters
identifier- The identifier associated with the updated record.
index- Its associated index.
LogRemove
event LogRemove(bytes32 indexed identifier, uint256 indexed index);Emitted when a record is removed.
Parameters
identifier- The identifier of the removed record.
index- The index associated with the removal.
Functions
insert
function insert(TypeALib.TypeA memory data) public returns (bytes32 identifier);Inserts a typed record into storage and returns its identifier.
Parameter
data- The TypeA struct to store.
Return value
identifier- The identifier of the stored record.
insertBytes
function insertBytes(bytes memory data) public returns (bytes32 identifier);Inserts a typed record supplied as a byte sequence. The implementation reconstructs the TypeA data from that sequence before storing it.
Parameter
data- The encoded TypeA record.
Return value
identifier- The identifier of the stored record.
remove
function remove(bytes32 identifier) public returns(uint256 index);Removes the record associated with the supplied identifier and returns its index.
Parameter
identifier- The identifier of the record to remove.
Return value
index- The index associated with the removed record.
update
function update(bytes32 identifier, TypeALib.TypeA memory data) public returns(bytes32 identifier);Updates an existing record using the supplied TypeA data.
Parameters
identifier- The identifier of the record to update.
data- The replacement TypeA data.
Return value
identifier- The identifier associated with the updated record. Whether it remains unchanged depends on the identifier derivation and update rules.
isStored
function isStored(bytes32 identifier) public view returns(bool stored);Determines whether a record associated with the supplied identifier exists.
Parameter
identifier- The identifier to check.
Return value
stored- True if the record is stored; otherwise false.
getByHash
function getByHash(bytes32 identifier) public view returns(TypeALib.TypeA memory data);Retrieves a TypeA record by its identifier.
Parameter
identifier- The identifier of the requested record.
Return value
data- The corresponding TypeA data.
getByIndex
function getByIndex(uint256 index) public view returns(TypeALib.TypeA memory data);Retrieves a TypeA record by its index in the storage collection.
Parameter
index- The index of the requested record.
Return value
data- The corresponding TypeA data.
count
function count() public view returns(uint256 counter);Returns the number of records currently stored.
Return value
counter- The number of stored TypeA records.
The code excerpts above are preserved from the original article. The TypeStorageContract excerpt describes intended signatures and data structures rather than a complete compilable implementation. A working implementation must supply function bodies, appropriate imports, compiler-compatible declarations, and access-control policies.
Rationale
Ethereum smart contracts are often designed as encapsulated objects whose state changes are mediated by application-specific functions. This resembles object-oriented programming (OOP), but independent contract interfaces and data layouts can complicate interoperability and reuse.
ERC-2157 instead separates data, business logic, and data structure definitions. Organizing public records around shared types can help independent developers build applications and services using the same datasets.
Defining a separate TypeRootContract rather than embedding additional storage fields directly into the dType registry also allows its interfaces to evolve independently.
Using common storage patterns for the dType registry and typed storage contracts may reduce duplicated development, testing, and auditing work.
The proposed pattern provides three principal capabilities:
- Addressing typed records through primary identifiers.
- Enumerating stored records through a common retrieval mechanism.
- Querying the total number of stored records.
Applications must still define the trust model, governance, and authorization rules for modifying these shared datasets. Standardized access does not by itself guarantee the correctness or integrity of the stored information.
Compatibility
The proposal introduces additional application-level contracts and interfaces rather than changing existing Ethereum consensus rules or contract behavior.
Its historical examples rely on ABIEncoderV2, which was experimental in older versions of Solidity. ABI coder v2 became the default in Solidity 0.8.
Reference implementation
The original article points to the following repository:
https://github.com/pipeos-one/dType/tree/master/contracts/contracts.
The historical URL is retained as written. The reference code has not been independently compiled or audited as part of this translation.
Citation
Loredana Cirstea (@loredanacirstea), Christian Tzurcanu (@ctzurcanu), "ERC-2157: dType Storage Extension - Decentralized Type System for EVM [DRAFT]," Ethereum Improvement Proposals, no. 2157, June 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2157.
Conclusion
ERC-2157 extends the dType system with a standardized storage interface, separating reusable type definitions from the contracts that hold instances of those types.
Questions are welcome via Twitter @cardene777.
Other publications:



