{"eip":7827,"title":"JSON Contract with Value Version Control","description":"Manage a JSON object onchain with per-key version history and a REST-like read interface.","authors":["lex-clinic (@lex-clinic)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2024-11-07","discussionsTo":"https://ethereum-magicians.org/t/erc-7827-json-smart-contract-with-value-version-control/21865","repo":"ERCs","label":"ERC-7827","officialUrl":"https://eips.ethereum.org/EIPS/eip-7827","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7827.md","url":"https://eips.huatuo.xyz/eip-7827/","tldr":{"en":"A small contract interface that stores a JSON object on-chain, returns it as a string, and keeps the full history of every key's values, aimed at developers coming from REST APIs.","ja":"JSON オブジェクトをオンチェーンに保存して文字列として返し、各キーの値の履歴をすべて保持する小さなコントラクトインターフェース。REST API の経験を持つ開発者向け。","ko":"JSON 객체를 온체인에 저장하고 문자열로 반환하며 각 키의 모든 값 이력을 보관하는 작은 컨트랙트 인터페이스. REST API 경험이 있는 개발자를 겨냥한다.","zh":"一个小型合约接口，在链上存储 JSON 对象，以字符串形式返回，并保留每个键所有取值的完整历史，面向有 REST API 背景的开发者。"},"tags":["json","storage","versioning","developer-experience"],"explainers":{"en":{"lang":"en","tldr":"A small contract interface that stores a JSON object on-chain, returns it as a string, and keeps the full history of every key's values, aimed at developers coming from REST APIs.","tags":["json","storage","versioning","developer-experience"],"related":[5219],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7827/","markdown":"## What problem does it solve?\n\nDevelopers from web backgrounds are used to REST endpoints that return JSON. Smart contracts, by contrast, expose typed getters, and reading structured data usually means learning the ABI for each contract.\n\nERC-7827 proposes a standard \"JSON contract\": you can fetch the whole object as a JSON string in one call, and every key keeps an append-only version history. The goal is to make on-chain data feel familiar to REST developers.\n\n## How it works\n\nThree functions:\n\n| Function | Behavior |\n| --- | --- |\n| `json()` | Returns the current object as a JSON string |\n| `version(key)` | Returns a JSON array string of all values the key has had, oldest first |\n| `write(keys, values, replace)` | Adds or updates keys; with `replace = false` it reverts if a key already exists |\n\nValues are treated as strings, leaving encoding efficiency to client libraries. Updates append to a key's history, so older values remain readable while `json()` shows only the latest.\n\nExample from the spec:\n\n1. `write([\"name\"], [\"Alice\"], false)` → `json()` is `{\"name\":\"Alice\"}`, history `[\"Alice\"]`.\n2. `write([\"name\"], [\"Bob\"], true)` → `{\"name\":\"Bob\"}`, history `[\"Alice\",\"Bob\"]`.\n3. `write([\"name\"], [\"Charlie\"], false)` → reverts, because `name` exists.\n\n## Sample code\n\nThe interface (non-normative in the spec) and a call from ethers v6:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC7827 {\n    function json() external view returns (string memory);\n    function version(string calldata key) external view returns (string memory);\n    function write(string[] calldata keys, string[] calldata values, bool replace) external;\n}\n```\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst doc = new Contract(address, [\n  \"function json() view returns (string)\",\n  \"function version(string key) view returns (string)\",\n], new JsonRpcProvider(process.env.RPC_URL));\n\nconst current = JSON.parse(await doc.json());          // { name: \"Bob\" }\nconst history = JSON.parse(await doc.version(\"name\")); // [\"Alice\", \"Bob\"]\n```\n\n## Things to know\n\n- **Status: Draft.** The interface may change.\n- The spec does not define access control for `write`; real deployments need to decide who may write.\n- Building JSON strings on-chain is gas-heavy, and histories only grow. The spec says implementations should guard against unbounded array writes and handle large objects carefully.\n- Values are strings, so numbers, booleans and nested objects need an agreed encoding between writer and reader.\n- For serving web-style responses from contracts more generally, see [ERC-5219](/eip-5219/).\n"},"ja":{"lang":"ja","tldr":"JSON オブジェクトをオンチェーンに保存して文字列として返し、各キーの値の履歴をすべて保持する小さなコントラクトインターフェース。REST API の経験を持つ開発者向け。","tags":["json","storage","versioning","developer-experience"],"related":[5219],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7827/","markdown":"## 何を解決するのか\n\nウェブ出身の開発者は、JSON を返す REST エンドポイントに慣れています。一方、スマートコントラクトは型付きのゲッターを公開しており、構造化データを読むには通常、コントラクトごとに ABI を学ぶ必要があります。\n\nERC-7827 は、標準の「JSON コントラクト」を提案します。オブジェクト全体を JSON 文字列として 1 回の呼び出しで取得でき、すべてのキーが追記専用のバージョン履歴を持ちます。オンチェーンのデータを REST 開発者にとって馴染みやすいものにすることが目標です。\n\n## 仕組み\n\n関数は 3 つです。\n\n| 関数 | 動作 |\n| --- | --- |\n| `json()` | 現在のオブジェクトを JSON 文字列として返す |\n| `version(key)` | そのキーがこれまでに持った値をすべて、古い順に並べた JSON 配列の文字列として返す |\n| `write(keys, values, replace)` | キーを追加または更新する。`replace = false` の場合、キーがすでに存在すると revert する |\n\n値は文字列として扱われ、エンコードの効率化はクライアントライブラリに任されています。更新はキーの履歴に追記されるため、古い値も読み取れるまま、`json()` には最新の値だけが表示されます。\n\n仕様の例:\n\n1. `write([\"name\"], [\"Alice\"], false)` → `json()` は `{\"name\":\"Alice\"}`、履歴は `[\"Alice\"]`。\n2. `write([\"name\"], [\"Bob\"], true)` → `{\"name\":\"Bob\"}`、履歴は `[\"Alice\",\"Bob\"]`。\n3. `write([\"name\"], [\"Charlie\"], false)` → `name` が存在するため revert。\n\n## サンプルコード\n\nインターフェース（仕様では非規範的）と、ethers v6 からの呼び出し:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC7827 {\n    function json() external view returns (string memory);\n    function version(string calldata key) external view returns (string memory);\n    function write(string[] calldata keys, string[] calldata values, bool replace) external;\n}\n```\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst doc = new Contract(address, [\n  \"function json() view returns (string)\",\n  \"function version(string key) view returns (string)\",\n], new JsonRpcProvider(process.env.RPC_URL));\n\nconst current = JSON.parse(await doc.json());          // { name: \"Bob\" }\nconst history = JSON.parse(await doc.version(\"name\")); // [\"Alice\", \"Bob\"]\n```\n\n## 知っておくべきこと\n\n- **ステータス: Draft。** インターフェースは変更される可能性があります。\n- 仕様は `write` のアクセス制御を定義していません。実際のデプロイでは、誰が書き込めるかを決める必要があります。\n- オンチェーンで JSON 文字列を組み立てるのは gas を大量に消費し、履歴は増える一方です。仕様は、実装が無制限の配列書き込みに対して防御し、大きなオブジェクトを慎重に扱うべきだとしています。\n- 値は文字列なので、数値、真偽値、ネストしたオブジェクトには、書き込み側と読み取り側で合意したエンコードが必要です。\n- コントラクトからウェブ形式のレスポンスを提供することについては、より一般的に [ERC-5219](/eip-5219/) を参照してください。\n"},"ko":{"lang":"ko","tldr":"JSON 객체를 온체인에 저장하고 문자열로 반환하며 각 키의 모든 값 이력을 보관하는 작은 컨트랙트 인터페이스. REST API 경험이 있는 개발자를 겨냥한다.","tags":["json","storage","versioning","developer-experience"],"related":[5219],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7827/","markdown":"## 어떤 문제를 해결하나요?\n\n웹 배경의 개발자는 JSON을 반환하는 REST 엔드포인트에 익숙합니다. 반면 스마트 컨트랙트는 타입이 있는 getter를 노출하므로, 구조화된 데이터를 읽으려면 보통 컨트랙트마다 ABI를 익혀야 합니다.\n\nERC-7827은 표준 \"JSON 컨트랙트\"를 제안합니다. 객체 전체를 JSON 문자열로 한 번의 호출로 가져올 수 있고, 모든 키가 추가만 가능한 버전 이력을 가집니다. 온체인 데이터를 REST 개발자에게 친숙하게 느껴지도록 하는 것이 목표입니다.\n\n## 어떻게 동작하나요?\n\n함수는 세 개입니다.\n\n| 함수 | 동작 |\n| --- | --- |\n| `json()` | 현재 객체를 JSON 문자열로 반환 |\n| `version(key)` | 해당 키가 가졌던 모든 값을 오래된 순으로 담은 JSON 배열 문자열을 반환 |\n| `write(keys, values, replace)` | 키를 추가하거나 갱신. `replace = false`이면 키가 이미 있을 때 revert |\n\n값은 문자열로 취급되며, 인코딩 효율은 클라이언트 라이브러리에 맡깁니다. 갱신은 키의 이력에 추가되므로 이전 값도 계속 읽을 수 있고, `json()`은 최신 값만 보여 줍니다.\n\n명세의 예:\n\n1. `write([\"name\"], [\"Alice\"], false)` → `json()`은 `{\"name\":\"Alice\"}`, 이력은 `[\"Alice\"]`.\n2. `write([\"name\"], [\"Bob\"], true)` → `{\"name\":\"Bob\"}`, 이력은 `[\"Alice\",\"Bob\"]`.\n3. `write([\"name\"], [\"Charlie\"], false)` → `name`이 이미 있으므로 revert.\n\n## 샘플 코드\n\n인터페이스(명세에서는 비규범)와 ethers v6에서의 호출:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC7827 {\n    function json() external view returns (string memory);\n    function version(string calldata key) external view returns (string memory);\n    function write(string[] calldata keys, string[] calldata values, bool replace) external;\n}\n```\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst doc = new Contract(address, [\n  \"function json() view returns (string)\",\n  \"function version(string key) view returns (string)\",\n], new JsonRpcProvider(process.env.RPC_URL));\n\nconst current = JSON.parse(await doc.json());          // { name: \"Bob\" }\nconst history = JSON.parse(await doc.version(\"name\")); // [\"Alice\", \"Bob\"]\n```\n\n## 알아둘 점\n\n- **상태: Draft.** 인터페이스는 바뀔 수 있습니다.\n- 명세는 `write`의 접근 제어를 정의하지 않습니다. 실제 배포에서는 누가 쓸 수 있는지 정해야 합니다.\n- 온체인에서 JSON 문자열을 만드는 것은 gas가 많이 들고, 이력은 늘어나기만 합니다. 명세는 구현체가 무한한 배열 쓰기를 방지하고 큰 객체를 신중하게 처리해야 한다고 말합니다.\n- 값이 문자열이므로 숫자, 불리언, 중첩 객체에는 쓰는 쪽과 읽는 쪽이 합의한 인코딩이 필요합니다.\n- 컨트랙트에서 웹 방식의 응답을 제공하는 더 일반적인 방법은 [ERC-5219](/eip-5219/)를 참고하세요.\n"},"zh":{"lang":"zh","tldr":"一个小型合约接口，在链上存储 JSON 对象，以字符串形式返回，并保留每个键所有取值的完整历史，面向有 REST API 背景的开发者。","tags":["json","storage","versioning","developer-experience"],"related":[5219],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7827/","markdown":"## 它解决什么问题？\n\n有 Web 背景的开发者习惯于返回 JSON 的 REST 端点。相比之下，智能合约暴露的是带类型的 getter，读取结构化数据通常意味着要为每个合约学习其 ABI。\n\nERC-7827 提出了一种标准的\"JSON 合约\"：一次调用即可把整个对象作为 JSON 字符串取回，并且每个键都有只追加的版本历史。目标是让链上数据对 REST 开发者来说更熟悉。\n\n## 它如何运作\n\n三个函数：\n\n| 函数 | 行为 |\n| --- | --- |\n| `json()` | 以 JSON 字符串形式返回当前对象 |\n| `version(key)` | 返回该键曾有过的所有值，按从旧到新的顺序排成 JSON 数组字符串 |\n| `write(keys, values, replace)` | 添加或更新键；当 `replace = false` 时，若键已存在则 revert |\n\n值被当作字符串处理，编码效率留给客户端库去优化。更新会追加到键的历史中，因此旧值仍然可读，而 `json()` 只显示最新值。\n\n规范中的示例：\n\n1. `write([\"name\"], [\"Alice\"], false)` → `json()` 为 `{\"name\":\"Alice\"}`，历史为 `[\"Alice\"]`。\n2. `write([\"name\"], [\"Bob\"], true)` → `{\"name\":\"Bob\"}`，历史为 `[\"Alice\",\"Bob\"]`。\n3. `write([\"name\"], [\"Charlie\"], false)` → revert，因为 `name` 已存在。\n\n## 示例代码\n\n接口（规范中为非规范性内容）以及使用 ethers v6 的调用：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC7827 {\n    function json() external view returns (string memory);\n    function version(string calldata key) external view returns (string memory);\n    function write(string[] calldata keys, string[] calldata values, bool replace) external;\n}\n```\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst doc = new Contract(address, [\n  \"function json() view returns (string)\",\n  \"function version(string key) view returns (string)\",\n], new JsonRpcProvider(process.env.RPC_URL));\n\nconst current = JSON.parse(await doc.json());          // { name: \"Bob\" }\nconst history = JSON.parse(await doc.version(\"name\")); // [\"Alice\", \"Bob\"]\n```\n\n## 需要注意\n\n- **状态：Draft。** 接口可能会变化。\n- 规范没有定义 `write` 的访问控制；实际部署时需要自行决定谁可以写入。\n- 在链上构造 JSON 字符串会消耗大量 gas，而且历史只增不减。规范指出，实现应防范无限制的数组写入，并谨慎处理大对象。\n- 值是字符串，因此数字、布尔值和嵌套对象需要写入方与读取方约定好编码方式。\n- 关于更一般地由合约提供 Web 风格的响应，请参见 [ERC-5219](/eip-5219/)。\n"}}}
