{"eip":5018,"title":"Filesystem-like Interface for Contracts","description":"An interface to provide access to binary objects similar to filesystems.","authors":["Qi Zhou (@qizhou)"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2022-04-18","discussionsTo":"https://ethereum-magicians.org/t/eip-5018-directory-standard/8958","repo":"ERCs","label":"ERC-5018","officialUrl":"https://eips.ethereum.org/EIPS/eip-5018","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5018.md","url":"https://eips.huatuo.xyz/eip-5018/","tldr":{"en":"A filesystem-style contract interface for storing named files of any size on-chain in chunks, so websites and other assets can be uploaded across many transactions and read back in one call.","ja":"任意サイズの名前付きファイルを、チャンク単位でオンチェーンに保存するファイルシステム型のコントラクトインターフェース。ウェブサイトなどのアセットを複数のトランザクションに分けてアップロードし、1 回の呼び出しで読み戻せる。","ko":"임의 크기의 이름 있는 파일을 청크 단위로 온체인에 저장하는 파일시스템 스타일의 컨트랙트 인터페이스. 웹사이트 등의 자산을 여러 트랜잭션에 걸쳐 업로드하고 한 번의 호출로 읽어 올 수 있다.","zh":"一个文件系统风格的合约接口，用于以分块方式在链上存储任意大小的命名文件，使网站等资源可以分多笔交易上传，并通过一次调用读回。"},"tags":["storage","web3-url","files","onchain-web"],"explainers":{"en":{"lang":"en","tldr":"A filesystem-style contract interface for storing named files of any size on-chain in chunks, so websites and other assets can be uploaded across many transactions and read back in one call.","tags":["storage","web3-url","files","onchain-web"],"related":[4804,6860,6944,7617],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5018/","markdown":"## What problem does it solve?\n\n[ERC-4804](/eip-4804/) lets a `web3://` URL point at a contract and fetch content from it like a web page. Real websites, though, are directories of files (HTML, CSS, images) that reference each other by relative path, and single files can be larger than one transaction can carry.\n\nERC-5018 standardizes a **directory contract**: files keyed by name, readable in one call, writable in chunks. A local folder and its on-chain copy then look the same, and relative links keep working.\n\n## How it works\n\nEach file is identified by a `bytes` name and stored as an ordered list of chunks.\n\nWhole-file operations:\n\n- `write(name, data)`: replace the file's content (payable, writer only).\n- `read(name) → (data, exist)`: return all chunks concatenated.\n- `size(name) → (size, chunks)` and `remove(name) → chunksRemoved`.\n- A `fallback` that treats calldata as a `/`-prefixed path and returns the file, which is what makes `web3://` path-style access work.\n\nChunk operations for large files:\n\n- `writeChunk(name, chunkId, data)`: may only replace an existing chunk or append the next one; `chunkId \u003e countChunks` fails.\n- `readChunk`, `chunkSize`, `countChunks`, `removeChunk`, `truncate(name, fromChunk)`.\n- `getChunkHash(name, chunkId)`: lets clients skip re-uploading unchanged chunks.\n\n`write` can be implemented as `writeChunk(name, 0, data)` followed by `truncate(name, 1)`. Who has write permission is up to the implementation.\n\n## Sample code\n\nThe interface, and uploading a large file in chunks with ethers v6:\n\n```solidity\ninterface IERC5018 {\n    function write(bytes memory name, bytes memory data) external payable;\n    function read(bytes memory name) external view returns (bytes memory data, bool exist);\n    function size(bytes memory name) external view returns (uint256 size, uint256 chunks);\n    function remove(bytes memory name) external returns (uint256 numOfChunksRemoved);\n    function countChunks(bytes memory name) external view returns (uint256);\n    function writeChunk(bytes memory name, uint256 chunkId, bytes memory chunkData) external payable;\n    function readChunk(bytes memory name, uint256 chunkId) external view returns (bytes memory, bool);\n    function chunkSize(bytes memory name, uint256 chunkId) external view returns (uint256, bool);\n    function removeChunk(bytes memory name, uint256 chunkId) external returns (bool);\n    function truncate(bytes memory name, uint256 chunkId) external returns (uint256);\n    function getChunkHash(bytes memory name, uint256 chunkId) external view returns (bytes32);\n}\n```\n\n```ts\nimport { Contract, toUtf8Bytes, keccak256 } from \"ethers\";\n\nconst CHUNK = 24 * 1024;\nasync function upload(dir: Contract, path: string, data: Uint8Array) {\n  const name = toUtf8Bytes(path);\n  for (let i = 0; i * CHUNK \u003c data.length; i++) {\n    const part = data.slice(i * CHUNK, (i + 1) * CHUNK);\n    if ((await dir.getChunkHash(name, i)) === keccak256(part)) continue; // unchanged (if impl hashes this way)\n    await (await dir.writeChunk(name, i, part)).wait();\n  }\n  await (await dir.truncate(name, Math.ceil(data.length / CHUNK))).wait(); // drop leftovers\n}\n```\n\n## Things to know\n\n- Status is **Stagnant**: the proposal is not progressing toward finalization.\n- The spec does not define how chunks are stored or hashed; the hash comparison above assumes keccak256 of the raw chunk and should be checked against the implementation.\n- On-chain storage is expensive; implementations may use other storage backends, but the interface does not say which.\n- No permission model is defined beyond \"an account with write permission\".\n- For the URL side see [ERC-4804](/eip-4804/) and its successor draft [ERC-6860](/eip-6860/); [ERC-7617](/eip-7617/) covers chunked responses for Web3 URLs.\n"},"ja":{"lang":"ja","tldr":"任意サイズの名前付きファイルを、チャンク単位でオンチェーンに保存するファイルシステム型のコントラクトインターフェース。ウェブサイトなどのアセットを複数のトランザクションに分けてアップロードし、1 回の呼び出しで読み戻せる。","tags":["storage","web3-url","files","onchain-web"],"related":[4804,6860,6944,7617],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5018/","markdown":"## 何を解決するのか\n\n[ERC-4804](/eip-4804/) では、`web3://` URL でコントラクトを指し、ウェブページのようにコンテンツを取得できます。しかし実際のウェブサイトは、相対パスで互いに参照し合うファイル（HTML、CSS、画像）のディレクトリであり、1 つのファイルが 1 トランザクションで運べるサイズを超えることもあります。\n\nERC-5018 は**ディレクトリコントラクト**を標準化します。ファイルは名前をキーにして、1 回の呼び出しで読み取れ、チャンク単位で書き込めます。これにより、ローカルのフォルダーとそのオンチェーンのコピーが同じように見え、相対リンクも機能し続けます。\n\n## 仕組み\n\n各ファイルは `bytes` 型の名前で識別され、順序付きのチャンクのリストとして保存されます。\n\nファイル全体に対する操作:\n\n- `write(name, data)`: ファイルの内容を置き換えます（payable、書き込み権限者のみ）。\n- `read(name) → (data, exist)`: すべてのチャンクを連結して返します。\n- `size(name) → (size, chunks)` と `remove(name) → chunksRemoved`。\n- `fallback`: calldata を `/` で始まるパスとして扱ってファイルを返します。これにより `web3://` のパス形式のアクセスが可能になります。\n\n大きなファイル向けのチャンク操作:\n\n- `writeChunk(name, chunkId, data)`: 既存のチャンクの置き換え、または次のチャンクの追加のみ可能です。`chunkId \u003e countChunks` は失敗します。\n- `readChunk`、`chunkSize`、`countChunks`、`removeChunk`、`truncate(name, fromChunk)`。\n- `getChunkHash(name, chunkId)`: クライアントが変更のないチャンクの再アップロードを省略できるようにします。\n\n`write` は、`writeChunk(name, 0, data)` に続けて `truncate(name, 1)` を呼ぶことで実装できます。誰に書き込み権限があるかは実装次第です。\n\n## サンプルコード\n\nインターフェースと、ethers v6 で大きなファイルをチャンクごとにアップロードする例:\n\n```solidity\ninterface IERC5018 {\n    function write(bytes memory name, bytes memory data) external payable;\n    function read(bytes memory name) external view returns (bytes memory data, bool exist);\n    function size(bytes memory name) external view returns (uint256 size, uint256 chunks);\n    function remove(bytes memory name) external returns (uint256 numOfChunksRemoved);\n    function countChunks(bytes memory name) external view returns (uint256);\n    function writeChunk(bytes memory name, uint256 chunkId, bytes memory chunkData) external payable;\n    function readChunk(bytes memory name, uint256 chunkId) external view returns (bytes memory, bool);\n    function chunkSize(bytes memory name, uint256 chunkId) external view returns (uint256, bool);\n    function removeChunk(bytes memory name, uint256 chunkId) external returns (bool);\n    function truncate(bytes memory name, uint256 chunkId) external returns (uint256);\n    function getChunkHash(bytes memory name, uint256 chunkId) external view returns (bytes32);\n}\n```\n\n```ts\nimport { Contract, toUtf8Bytes, keccak256 } from \"ethers\";\n\nconst CHUNK = 24 * 1024;\nasync function upload(dir: Contract, path: string, data: Uint8Array) {\n  const name = toUtf8Bytes(path);\n  for (let i = 0; i * CHUNK \u003c data.length; i++) {\n    const part = data.slice(i * CHUNK, (i + 1) * CHUNK);\n    if ((await dir.getChunkHash(name, i)) === keccak256(part)) continue; // unchanged (if impl hashes this way)\n    await (await dir.writeChunk(name, i, part)).wait();\n  }\n  await (await dir.truncate(name, Math.ceil(data.length / CHUNK))).wait(); // drop leftovers\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。提案は最終化に向けて進んでいません。\n- 仕様はチャンクの保存方法やハッシュ方法を定義していません。上のハッシュ比較は、生のチャンクの keccak256 を前提としているため、実装に照らして確認してください。\n- オンチェーンのストレージは高価です。実装は他のストレージバックエンドを使ってもかまいませんが、インターフェースはそれがどれかを示しません。\n- 「書き込み権限を持つアカウント」以上の権限モデルは定義されていません。\n- URL 側については [ERC-4804](/eip-4804/) とその後継ドラフトの [ERC-6860](/eip-6860/) を参照してください。[ERC-7617](/eip-7617/) は Web3 URL のチャンク化されたレスポンスを扱います。\n"},"ko":{"lang":"ko","tldr":"임의 크기의 이름 있는 파일을 청크 단위로 온체인에 저장하는 파일시스템 스타일의 컨트랙트 인터페이스. 웹사이트 등의 자산을 여러 트랜잭션에 걸쳐 업로드하고 한 번의 호출로 읽어 올 수 있다.","tags":["storage","web3-url","files","onchain-web"],"related":[4804,6860,6944,7617],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5018/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-4804](/eip-4804/)는 `web3://` URL로 컨트랙트를 가리키고 웹 페이지처럼 콘텐츠를 가져올 수 있게 합니다. 하지만 실제 웹사이트는 상대 경로로 서로를 참조하는 파일(HTML, CSS, 이미지)의 디렉터리이고, 파일 하나가 한 트랜잭션에 담을 수 있는 크기보다 클 수도 있습니다.\n\nERC-5018은 **디렉터리 컨트랙트**를 표준화합니다. 파일은 이름을 키로 하여 한 번의 호출로 읽을 수 있고 청크 단위로 쓸 수 있습니다. 그러면 로컬 폴더와 그 온체인 사본이 똑같이 보이고, 상대 링크도 계속 동작합니다.\n\n## 어떻게 동작하나요?\n\n각 파일은 `bytes` 이름으로 식별되며 순서가 있는 청크 목록으로 저장됩니다.\n\n파일 전체 단위 작업:\n\n- `write(name, data)`: 파일 내용을 교체합니다(payable, 쓰기 권한자만).\n- `read(name) → (data, exist)`: 모든 청크를 이어 붙여 반환합니다.\n- `size(name) → (size, chunks)`와 `remove(name) → chunksRemoved`.\n- calldata를 `/`로 시작하는 경로로 간주해 파일을 반환하는 `fallback`. 이것이 `web3://` 경로 방식 접근을 가능하게 합니다.\n\n큰 파일을 위한 청크 단위 작업:\n\n- `writeChunk(name, chunkId, data)`: 기존 청크를 교체하거나 다음 청크를 추가하는 것만 가능하며, `chunkId \u003e countChunks`는 실패합니다.\n- `readChunk`, `chunkSize`, `countChunks`, `removeChunk`, `truncate(name, fromChunk)`.\n- `getChunkHash(name, chunkId)`: 클라이언트가 바뀌지 않은 청크의 재업로드를 건너뛸 수 있게 합니다.\n\n`write`는 `writeChunk(name, 0, data)` 다음에 `truncate(name, 1)`을 호출하는 방식으로 구현할 수 있습니다. 누구에게 쓰기 권한이 있는지는 구현에 달려 있습니다.\n\n## 샘플 코드\n\n인터페이스와, ethers v6로 큰 파일을 청크 단위로 업로드하는 코드:\n\n```solidity\ninterface IERC5018 {\n    function write(bytes memory name, bytes memory data) external payable;\n    function read(bytes memory name) external view returns (bytes memory data, bool exist);\n    function size(bytes memory name) external view returns (uint256 size, uint256 chunks);\n    function remove(bytes memory name) external returns (uint256 numOfChunksRemoved);\n    function countChunks(bytes memory name) external view returns (uint256);\n    function writeChunk(bytes memory name, uint256 chunkId, bytes memory chunkData) external payable;\n    function readChunk(bytes memory name, uint256 chunkId) external view returns (bytes memory, bool);\n    function chunkSize(bytes memory name, uint256 chunkId) external view returns (uint256, bool);\n    function removeChunk(bytes memory name, uint256 chunkId) external returns (bool);\n    function truncate(bytes memory name, uint256 chunkId) external returns (uint256);\n    function getChunkHash(bytes memory name, uint256 chunkId) external view returns (bytes32);\n}\n```\n\n```ts\nimport { Contract, toUtf8Bytes, keccak256 } from \"ethers\";\n\nconst CHUNK = 24 * 1024;\nasync function upload(dir: Contract, path: string, data: Uint8Array) {\n  const name = toUtf8Bytes(path);\n  for (let i = 0; i * CHUNK \u003c data.length; i++) {\n    const part = data.slice(i * CHUNK, (i + 1) * CHUNK);\n    if ((await dir.getChunkHash(name, i)) === keccak256(part)) continue; // unchanged (if impl hashes this way)\n    await (await dir.writeChunk(name, i, part)).wait();\n  }\n  await (await dir.truncate(name, Math.ceil(data.length / CHUNK))).wait(); // drop leftovers\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 제안이 최종 확정을 향해 진행되지 않고 있습니다.\n- 명세는 청크를 어떻게 저장하거나 해시하는지 정의하지 않습니다. 위의 해시 비교는 원본 청크의 keccak256을 가정하므로 실제 구현에 맞는지 확인해야 합니다.\n- 온체인 스토리지는 비쌉니다. 구현은 다른 스토리지 백엔드를 사용할 수 있지만 인터페이스는 어느 것인지 알려 주지 않습니다.\n- \"쓰기 권한이 있는 계정\" 이상의 권한 모델은 정의되어 있지 않습니다.\n- URL 쪽은 [ERC-4804](/eip-4804/)와 그 후속 초안인 [ERC-6860](/eip-6860/)을 참고하세요. [ERC-7617](/eip-7617/)은 Web3 URL의 청크 응답을 다룹니다.\n"},"zh":{"lang":"zh","tldr":"一个文件系统风格的合约接口，用于以分块方式在链上存储任意大小的命名文件，使网站等资源可以分多笔交易上传，并通过一次调用读回。","tags":["storage","web3-url","files","onchain-web"],"related":[4804,6860,6944,7617],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5018/","markdown":"## 它解决什么问题？\n\n[ERC-4804](/eip-4804/) 让 `web3://` URL 指向某个合约，并像网页一样从中获取内容。然而真实的网站是由文件（HTML、CSS、图片）组成的目录，这些文件通过相对路径互相引用，而单个文件也可能大于一笔交易所能携带的数据量。\n\nERC-5018 标准化了一种**目录合约**：文件以名称为键，可一次调用读取，可分块写入。这样本地文件夹与其链上副本看起来一致，相对链接也能继续工作。\n\n## 它如何运作\n\n每个文件由一个 `bytes` 类型的名称标识，并存储为有序的分块列表。\n\n整文件操作：\n\n- `write(name, data)`：替换文件内容（payable，仅限有写权限者）。\n- `read(name) → (data, exist)`：返回拼接后的所有分块。\n- `size(name) → (size, chunks)` 和 `remove(name) → chunksRemoved`。\n- 一个 `fallback`，把 calldata 视为以 `/` 开头的路径并返回对应文件，这正是让 `web3://` 路径式访问得以工作的原因。\n\n面向大文件的分块操作：\n\n- `writeChunk(name, chunkId, data)`：只能替换已有分块或追加下一个分块；`chunkId \u003e countChunks` 会失败。\n- `readChunk`、`chunkSize`、`countChunks`、`removeChunk`、`truncate(name, fromChunk)`。\n- `getChunkHash(name, chunkId)`：让客户端可以跳过未改动分块的重复上传。\n\n`write` 可以实现为 `writeChunk(name, 0, data)` 再接 `truncate(name, 1)`。谁拥有写权限由具体实现决定。\n\n## 示例代码\n\n接口，以及使用 ethers v6 分块上传大文件：\n\n```solidity\ninterface IERC5018 {\n    function write(bytes memory name, bytes memory data) external payable;\n    function read(bytes memory name) external view returns (bytes memory data, bool exist);\n    function size(bytes memory name) external view returns (uint256 size, uint256 chunks);\n    function remove(bytes memory name) external returns (uint256 numOfChunksRemoved);\n    function countChunks(bytes memory name) external view returns (uint256);\n    function writeChunk(bytes memory name, uint256 chunkId, bytes memory chunkData) external payable;\n    function readChunk(bytes memory name, uint256 chunkId) external view returns (bytes memory, bool);\n    function chunkSize(bytes memory name, uint256 chunkId) external view returns (uint256, bool);\n    function removeChunk(bytes memory name, uint256 chunkId) external returns (bool);\n    function truncate(bytes memory name, uint256 chunkId) external returns (uint256);\n    function getChunkHash(bytes memory name, uint256 chunkId) external view returns (bytes32);\n}\n```\n\n```ts\nimport { Contract, toUtf8Bytes, keccak256 } from \"ethers\";\n\nconst CHUNK = 24 * 1024;\nasync function upload(dir: Contract, path: string, data: Uint8Array) {\n  const name = toUtf8Bytes(path);\n  for (let i = 0; i * CHUNK \u003c data.length; i++) {\n    const part = data.slice(i * CHUNK, (i + 1) * CHUNK);\n    if ((await dir.getChunkHash(name, i)) === keccak256(part)) continue; // unchanged (if impl hashes this way)\n    await (await dir.writeChunk(name, i, part)).wait();\n  }\n  await (await dir.truncate(name, Math.ceil(data.length / CHUNK))).wait(); // drop leftovers\n}\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**：该提案没有朝最终定稿推进。\n- 规范没有定义分块如何存储或哈希；上面的哈希比较假设使用原始分块的 keccak256，应对照具体实现进行检查。\n- 链上存储很昂贵；实现可以使用其他存储后端，但接口并未说明是哪一种。\n- 除了\"拥有写权限的账户\"之外，没有定义任何权限模型。\n- URL 方面请参阅 [ERC-4804](/eip-4804/) 及其后继草案 [ERC-6860](/eip-6860/)；[ERC-7617](/eip-7617/) 涵盖了 Web3 URL 的分块响应。\n"}}}
