---
eip: 7813
label: ERC-7813
title: Store, Table-Based Introspectable Storage
status: Final
type: Standards Track
category: ERC
created: 2024-11-08
official: https://eips.ethereum.org/EIPS/eip-7813
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7813.md
canonical: https://eips.huatuo.xyz/eip-7813/
lang: en
tldr: "A storage standard that organizes contract data into typed tables with schemas registered on-chain and standard events for every write, so indexers can replicate any contract's state automatically without custom getters."
tags: [storage, indexing, tables, events, mud]
---

# ERC-7813: Store, Table-Based Introspectable Storage

> On-chain tables for automatic indexing and introspectable state

**TL;DR:** A storage standard that organizes contract data into typed tables with schemas registered on-chain and standard events for every write, so indexers can replicate any contract's state automatically without custom getters.

## What problem does it solve?

In a typical contract, data lives in Solidity variables and mappings. To read it, others need a getter written specifically for it. To index it, someone writes a custom subgraph or indexer that knows that contract's events. Changing the data layout breaks those integrations, and upgrades must carefully preserve the storage layout.

ERC-7813 defines a **Store**: data is kept in tables whose key and value schemas are themselves stored on-chain, and every write emits one of four standard events. Any generic indexer can then rebuild every table of every Store, and any contract can read any record through a single interface. It standardizes the Store model used by the MUD framework.

## How it works

- **Tables** are identified by a 32-byte `ResourceId`: two bytes for the type (`"tb"` on-chain, `"ot"` off-chain, which only emits events), then a 30-byte name.
- **Records** are addressed by a key tuple (`bytes32[]`).
- Each table has a **key schema** (static types only) and a **value schema** (up to 28 fields, at most 5 of them dynamic). A `Schema` packs field types into one `bytes32`, one byte per field (`0x00`–`0x1F` for `uint8`…`uint256`, `0x61` `address`, `0xC4` `bytes`, `0xC5` `string`, and so on). Arrays of dynamic types such as `string[]` are not allowed.
- **Encoding**: static fields are tightly packed; dynamic fields are concatenated without lengths, and their lengths go into a single `EncodedLengths` word. A record is `(staticData, encodedLengths, dynamicData)`.
- **Read interface**: `getRecord`, `getField`, `getFieldLength`. Writes are implementation-specific.
- **Events**: `Store_SetRecord` (full overwrite), `Store_SpliceStaticData` and `Store_SpliceDynamicData` (partial updates, cheaper than re-emitting the whole record), `Store_DeleteRecord`. On-chain table contents MUST always equal what replaying these events gives.
- A special **`Tables`** table stores each table's field layout, schemas and key/field names. It registers itself first, so an indexer that knows only this one table ID can decode everything else.

## Sample code

The read interface:

```solidity
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.8.24;

type ResourceId is bytes32;
type EncodedLengths is bytes32;

interface IStore {
    function getRecord(ResourceId tableId, bytes32[] calldata keyTuple)
        external view
        returns (bytes memory staticData, EncodedLengths encodedLengths, bytes memory dynamicData);

    function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex)
        external view returns (bytes memory data);

    function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex)
        external view returns (uint256);
}
```

Following a Store from TypeScript (ethers v6):

```ts
const store = new Contract(STORE, [
  "event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)",
  "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)",
], provider);

store.on("Store_SetRecord", (tableId, keyTuple, staticData, encodedLengths, dynamicData) => {
  db.upsert(tableId, keyTuple, { staticData, encodedLengths, dynamicData });
});
```

## Things to know

- **Status: Final.**
- The standard only defines reads. Each implementation must add its own access control for writes.
- Everything in a Store is readable by any other contract through `getRecord`/`getField`, unlike ordinary contract storage, which other contracts cannot read without a getter. Do not treat any table as private.
- Off-chain tables (`"ot"`) are a cheap way to publish data via events only; their content cannot be read on-chain.
- The `Tables` table ID is fixed: `0x746273746f72650000000000000000005461626c657300000000000000000000` (`"tb"` + `"store"` + `"Tables"`).


---

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