---
eip: 5018
label: ERC-5018
title: Filesystem-like Interface for Contracts
status: Stagnant
type: Standards Track
category: ERC
created: 2022-04-18
official: https://eips.ethereum.org/EIPS/eip-5018
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5018.md
canonical: https://eips.huatuo.xyz/eip-5018/
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]
---

# ERC-5018: Filesystem-like Interface for Contracts

> An interface to provide access to binary objects similar to filesystems.

**TL;DR:** 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.

## What problem does it solve?

[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.

ERC-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.

## How it works

Each file is identified by a `bytes` name and stored as an ordered list of chunks.

Whole-file operations:

- `write(name, data)`: replace the file's content (payable, writer only).
- `read(name) → (data, exist)`: return all chunks concatenated.
- `size(name) → (size, chunks)` and `remove(name) → chunksRemoved`.
- A `fallback` that treats calldata as a `/`-prefixed path and returns the file, which is what makes `web3://` path-style access work.

Chunk operations for large files:

- `writeChunk(name, chunkId, data)`: may only replace an existing chunk or append the next one; `chunkId > countChunks` fails.
- `readChunk`, `chunkSize`, `countChunks`, `removeChunk`, `truncate(name, fromChunk)`.
- `getChunkHash(name, chunkId)`: lets clients skip re-uploading unchanged chunks.

`write` can be implemented as `writeChunk(name, 0, data)` followed by `truncate(name, 1)`. Who has write permission is up to the implementation.

## Sample code

The interface, and uploading a large file in chunks with ethers v6:

```solidity
interface IERC5018 {
    function write(bytes memory name, bytes memory data) external payable;
    function read(bytes memory name) external view returns (bytes memory data, bool exist);
    function size(bytes memory name) external view returns (uint256 size, uint256 chunks);
    function remove(bytes memory name) external returns (uint256 numOfChunksRemoved);
    function countChunks(bytes memory name) external view returns (uint256);
    function writeChunk(bytes memory name, uint256 chunkId, bytes memory chunkData) external payable;
    function readChunk(bytes memory name, uint256 chunkId) external view returns (bytes memory, bool);
    function chunkSize(bytes memory name, uint256 chunkId) external view returns (uint256, bool);
    function removeChunk(bytes memory name, uint256 chunkId) external returns (bool);
    function truncate(bytes memory name, uint256 chunkId) external returns (uint256);
    function getChunkHash(bytes memory name, uint256 chunkId) external view returns (bytes32);
}
```

```ts
import { Contract, toUtf8Bytes, keccak256 } from "ethers";

const CHUNK = 24 * 1024;
async function upload(dir: Contract, path: string, data: Uint8Array) {
  const name = toUtf8Bytes(path);
  for (let i = 0; i * CHUNK < data.length; i++) {
    const part = data.slice(i * CHUNK, (i + 1) * CHUNK);
    if ((await dir.getChunkHash(name, i)) === keccak256(part)) continue; // unchanged (if impl hashes this way)
    await (await dir.writeChunk(name, i, part)).wait();
  }
  await (await dir.truncate(name, Math.ceil(data.length / CHUNK))).wait(); // drop leftovers
}
```

## Things to know

- Status is **Stagnant**: the proposal is not progressing toward finalization.
- 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.
- On-chain storage is expensive; implementations may use other storage backends, but the interface does not say which.
- No permission model is defined beyond "an account with write permission".
- 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.


---

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