{"eip":7818,"title":"Expirable ERC-20","description":"An ERC-20 extension for creating fungible tokens with expiration, supporting time-limited use cases.","authors":["sirawt (@MASDXI)","ADISAKBOONMARK (@ADISAKBOONMARK)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2024-11-13","requires":[20],"discussionsTo":"https://ethereum-magicians.org/t/erc-7818-expirable-erc20/21655","repo":"ERCs","label":"ERC-7818","officialUrl":"https://eips.ethereum.org/EIPS/eip-7818","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7818.md","url":"https://eips.huatuo.xyz/eip-7818/","tldr":{"en":"An ERC-20 extension where tokens belong to epochs and expire after a set number of them, for loyalty points, prepaid credits, game items or bonds that should lapse automatically.","ja":"トークンがエポックに属し、一定数のエポックが過ぎると失効する ERC-20 拡張。ポイント、プリペイドクレジット、ゲーム内アイテム、債券など、自動的に失効させたいものに向く。","ko":"토큰이 에포크(epoch)에 속하고 정해진 수의 에포크가 지나면 만료되는 ERC-20 확장. 자동으로 소멸해야 하는 포인트, 선불 크레딧, 게임 아이템, 채권 등에 쓸 수 있다.","zh":"一个 ERC-20 扩展，代币归属于各个纪元（epoch），并在经过设定数量的纪元后过期，适用于应当自动失效的积分、预付额度、游戏道具或债券。"},"tags":["token","erc20","expiration","epochs","loyalty"],"explainers":{"en":{"lang":"en","tldr":"An ERC-20 extension where tokens belong to epochs and expire after a set number of them, for loyalty points, prepaid credits, game items or bonds that should lapse automatically.","tags":["token","erc20","expiration","epochs","loyalty"],"related":[20],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7818/","markdown":"## What problem does it solve?\n\nMany real-world balances are not meant to last forever: loyalty points, promotional credits, mobile data allowances, game currencies or instruments with a maturity date. With a plain [ERC-20](/eip-20/), expiring them means running a job that burns balances, which is costly, centralised and easy to get wrong.\n\nERC-7818 makes expiry part of the token. Expired tokens simply stop counting, with no write transaction needed.\n\n## How it works\n\nTime is divided into **epochs**, measured either in blocks (`BLOCKS_BASED`) or in seconds (`TIME_BASED`). Tokens received in an epoch stay valid for `validityDuration()` epochs. After that the epoch is expired and its tokens are unusable.\n\nBecause the current epoch can be computed with a read, expiry is \"lazy\": nothing has to run when tokens expire.\n\nThe standard ERC-20 functions change meaning slightly:\n\n- `balanceOf` returns only **non-expired** tokens.\n- `transfer` / `transferFrom` may only move non-expired tokens, and must revert or return `false` otherwise. Implementations may spend the soonest-expiring tokens first.\n- `totalSupply` is hard to compute when tokens silently expire, so the spec says it **should** return `0` or `type(uint256).max`.\n\nNew functions:\n\n| Function | Purpose |\n| --- | --- |\n| `currentEpoch()` | The latest epoch |\n| `epochLength()`, `epochType()` | Epoch size and unit |\n| `validityDuration()` | How many epochs tokens stay valid |\n| `isEpochExpired(epoch)` | Expiry check |\n| `balanceOfAtEpoch(epoch, account)` | Balance from one epoch (0 if expired) |\n| `transferAtEpoch` / `transferFromAtEpoch` | Move tokens from a specific epoch |\n\nExample from the spec: balances of 100, 150 and 200 in epochs 1, 2 and 3, with the current epoch 3 and validity reaching one epoch back. The usable balance is 150 + 200 = 350.\n\n## Sample code\n\nReading an expirable balance (ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst abi = [\n  \"function balanceOf(address) view returns (uint256)\",\n  \"function currentEpoch() view returns (uint256)\",\n  \"function validityDuration() view returns (uint256)\",\n  \"function balanceOfAtEpoch(uint256 epoch, address account) view returns (uint256)\",\n];\nconst token = new Contract(tokenAddress, abi, new JsonRpcProvider(process.env.RPC_URL));\n\nconst usable = await token.balanceOf(user);           // non-expired only\nconst now: bigint = await token.currentEpoch();\nconst validity: bigint = await token.validityDuration();\n\nfor (let e = now; e \u003e= 0n \u0026\u0026 now - e \u003c= validity; e--) {\n  console.log(`epoch ${e}:`, await token.balanceOfAtEpoch(e, user)); // 0 once expired\n}\nconsole.log(\"usable:\", usable);\n```\n\n## Things to know\n\n- **Status: Final.**\n- Tools that assume balances only change through `Transfer` events will be wrong: balances drop silently when epochs expire. `totalSupply` is not meaningful either.\n- Expiring tokens inside DEX pools or lending protocols can expire while deposited; most DeFi integrations are not built for this.\n- Spending across many small epoch buckets can use a lot of gas, and very fragmented balances risk hitting the block gas limit.\n- Time-based epochs depend on `block.timestamp`. The reference implementation uses block numbers instead, partly because of concerns about L2 halts.\n"},"ja":{"lang":"ja","tldr":"トークンがエポックに属し、一定数のエポックが過ぎると失効する ERC-20 拡張。ポイント、プリペイドクレジット、ゲーム内アイテム、債券など、自動的に失効させたいものに向く。","tags":["token","erc20","expiration","epochs","loyalty"],"related":[20],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7818/","markdown":"## 何を解決するのか\n\n現実世界の残高の多くは、永続することを意図していません。ロイヤルティポイント、販促クレジット、モバイルデータの利用枠、ゲーム内通貨、満期のある金融商品などです。素の [ERC-20](/eip-20/) で失効させるには、残高をバーンするジョブを走らせる必要があり、コストがかかり、中央集権的で、間違えやすい方法になります。\n\nERC-7818 は、失効をトークンの一部にします。失効したトークンは単にカウントされなくなり、書き込みトランザクションは不要です。\n\n## 仕組み\n\n時間は**エポック**に分割され、ブロック数（`BLOCKS_BASED`）または秒数（`TIME_BASED`）で計測されます。あるエポックで受け取ったトークンは、`validityDuration()` で示される数のエポックの間、有効です。その後はそのエポックが失効し、トークンは使えなくなります。\n\n現在のエポックは読み取りだけで計算できるため、失効は「遅延評価」です。トークンが失効するときに実行しなければならない処理はありません。\n\n標準の ERC-20 関数は、意味が少し変わります。\n\n- `balanceOf` は**失効していない**トークンだけを返します。\n- `transfer` / `transferFrom` は、失効していないトークンだけを移動でき、そうでなければリバートするか `false` を返さなければなりません。実装は、失効が最も近いトークンから先に使ってもかまいません。\n- トークンが黙って失効すると `totalSupply` の計算は困難になるため、仕様は `0` または `type(uint256).max` を返す**べき**としています。\n\n新しい関数:\n\n| 関数 | 役割 |\n| --- | --- |\n| `currentEpoch()` | 最新のエポック |\n| `epochLength()`, `epochType()` | エポックの長さと単位 |\n| `validityDuration()` | トークンが有効なエポック数 |\n| `isEpochExpired(epoch)` | 失効のチェック |\n| `balanceOfAtEpoch(epoch, account)` | あるエポックの残高（失効していれば 0） |\n| `transferAtEpoch` / `transferFromAtEpoch` | 特定のエポックのトークンを移動 |\n\n仕様の例: エポック 1、2、3 の残高がそれぞれ 100、150、200 で、現在のエポックが 3、有効期間が 1 エポック前まで遡る場合、使える残高は 150 + 200 = 350 です。\n\n## サンプルコード\n\n失効する残高の読み取り（ethers v6）:\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst abi = [\n  \"function balanceOf(address) view returns (uint256)\",\n  \"function currentEpoch() view returns (uint256)\",\n  \"function validityDuration() view returns (uint256)\",\n  \"function balanceOfAtEpoch(uint256 epoch, address account) view returns (uint256)\",\n];\nconst token = new Contract(tokenAddress, abi, new JsonRpcProvider(process.env.RPC_URL));\n\nconst usable = await token.balanceOf(user);           // non-expired only\nconst now: bigint = await token.currentEpoch();\nconst validity: bigint = await token.validityDuration();\n\nfor (let e = now; e \u003e= 0n \u0026\u0026 now - e \u003c= validity; e--) {\n  console.log(`epoch ${e}:`, await token.balanceOfAtEpoch(e, user)); // 0 once expired\n}\nconsole.log(\"usable:\", usable);\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final。**\n- 残高が `Transfer` イベントによってのみ変化すると仮定するツールは、誤った結果になります。エポックが失効すると、残高は黙って減るからです。`totalSupply` も意味のある値ではありません。\n- DEX のプールやレンディングプロトコルの中のトークンは、預け入れている間に失効する可能性があります。ほとんどの DeFi 連携は、これを想定して作られていません。\n- 多数の小さなエポックのバケットをまたいで使うと、ガスを大量に消費することがあり、極端に細分化された残高はブロックのガスリミットに達するリスクがあります。\n- 時間ベースのエポックは `block.timestamp` に依存します。リファレンス実装は、L2 の停止への懸念もあって、代わりにブロック番号を使っています。\n"},"ko":{"lang":"ko","tldr":"토큰이 에포크(epoch)에 속하고 정해진 수의 에포크가 지나면 만료되는 ERC-20 확장. 자동으로 소멸해야 하는 포인트, 선불 크레딧, 게임 아이템, 채권 등에 쓸 수 있다.","tags":["token","erc20","expiration","epochs","loyalty"],"related":[20],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7818/","markdown":"## 어떤 문제를 해결하나요?\n\n현실 세계의 많은 잔액은 영원히 유지되도록 만들어지지 않습니다. 로열티 포인트, 프로모션 크레딧, 모바일 데이터 제공량, 게임 화폐, 만기가 있는 금융 상품 등이 그렇습니다. 일반 [ERC-20](/eip-20/)으로 이를 만료시키려면 잔액을 소각하는 작업을 돌려야 하는데, 비용이 많이 들고 중앙화되어 있으며 실수하기 쉽습니다.\n\nERC-7818은 만료를 토큰의 일부로 만듭니다. 만료된 토큰은 그냥 계산되지 않으며, 쓰기 트랜잭션이 필요 없습니다.\n\n## 어떻게 동작하나요?\n\n시간은 블록 수(`BLOCKS_BASED`) 또는 초(`TIME_BASED`)로 측정되는 **에포크**로 나뉩니다. 어떤 에포크에서 받은 토큰은 `validityDuration()`개의 에포크 동안 유효합니다. 그 후에는 해당 에포크가 만료되어 토큰을 쓸 수 없습니다.\n\n현재 에포크는 읽기만으로 계산할 수 있으므로 만료는 \"지연(lazy)\" 방식입니다. 토큰이 만료될 때 실행해야 할 것이 없습니다.\n\n표준 ERC-20 함수는 의미가 조금 바뀝니다.\n\n- `balanceOf`는 **만료되지 않은** 토큰만 반환합니다.\n- `transfer` / `transferFrom`은 만료되지 않은 토큰만 옮길 수 있으며, 그렇지 않으면 리버트하거나 `false`를 반환해야 합니다. 구현은 만료가 가장 임박한 토큰부터 쓸 수 있습니다.\n- 토큰이 조용히 만료되면 `totalSupply`를 계산하기 어려우므로, 명세는 `0` 또는 `type(uint256).max`를 반환**해야 한다**고 합니다.\n\n새 함수:\n\n| 함수 | 용도 |\n| --- | --- |\n| `currentEpoch()` | 최신 에포크 |\n| `epochLength()`, `epochType()` | 에포크의 크기와 단위 |\n| `validityDuration()` | 토큰이 유효한 에포크 수 |\n| `isEpochExpired(epoch)` | 만료 확인 |\n| `balanceOfAtEpoch(epoch, account)` | 한 에포크의 잔액(만료되었으면 0) |\n| `transferAtEpoch` / `transferFromAtEpoch` | 특정 에포크의 토큰을 이동 |\n\n명세의 예: 에포크 1, 2, 3의 잔액이 각각 100, 150, 200이고 현재 에포크가 3이며 유효 기간이 한 에포크 전까지 거슬러 올라갑니다. 사용할 수 있는 잔액은 150 + 200 = 350입니다.\n\n## 샘플 코드\n\n만료되는 잔액 읽기(ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst abi = [\n  \"function balanceOf(address) view returns (uint256)\",\n  \"function currentEpoch() view returns (uint256)\",\n  \"function validityDuration() view returns (uint256)\",\n  \"function balanceOfAtEpoch(uint256 epoch, address account) view returns (uint256)\",\n];\nconst token = new Contract(tokenAddress, abi, new JsonRpcProvider(process.env.RPC_URL));\n\nconst usable = await token.balanceOf(user);           // non-expired only\nconst now: bigint = await token.currentEpoch();\nconst validity: bigint = await token.validityDuration();\n\nfor (let e = now; e \u003e= 0n \u0026\u0026 now - e \u003c= validity; e--) {\n  console.log(`epoch ${e}:`, await token.balanceOfAtEpoch(e, user)); // 0 once expired\n}\nconsole.log(\"usable:\", usable);\n```\n\n## 알아둘 점\n\n- **상태: Final.**\n- 잔액이 `Transfer` 이벤트로만 바뀐다고 가정하는 도구는 틀린 값을 보여 줍니다. 에포크가 만료되면 잔액이 조용히 줄어듭니다. `totalSupply`도 의미가 없습니다.\n- DEX 풀이나 대출 프로토콜 안의 만료되는 토큰은 예치된 동안 만료될 수 있으며, 대부분의 DeFi 연동은 이를 염두에 두고 만들어지지 않았습니다.\n- 작은 에포크 버킷 여러 개에 걸쳐 토큰을 쓰면 가스가 많이 들 수 있고, 잔액이 지나치게 조각나 있으면 블록 가스 한도에 걸릴 위험이 있습니다.\n- 시간 기반 에포크는 `block.timestamp`에 의존합니다. 레퍼런스 구현은 L2 중단에 대한 우려도 있어 대신 블록 번호를 사용합니다.\n"},"zh":{"lang":"zh","tldr":"一个 ERC-20 扩展，代币归属于各个纪元（epoch），并在经过设定数量的纪元后过期，适用于应当自动失效的积分、预付额度、游戏道具或债券。","tags":["token","erc20","expiration","epochs","loyalty"],"related":[20],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7818/","markdown":"## 它解决什么问题？\n\n现实中的许多余额并不打算永久存在：忠诚度积分、促销额度、手机流量额度、游戏货币，或有到期日的工具。使用普通的 [ERC-20](/eip-20/)，要让它们过期就得运行一个销毁余额的任务，成本高、中心化，而且容易出错。\n\nERC-7818 把过期变成代币的一部分。过期的代币直接不再被计入，无需任何写入交易。\n\n## 它如何运作\n\n时间被划分为**纪元（epoch）**，以区块数（`BLOCKS_BASED`）或秒数（`TIME_BASED`）计量。在某个纪元收到的代币在 `validityDuration()` 个纪元内保持有效。之后该纪元就过期了，其中的代币不可使用。\n\n由于当前纪元可以通过读取计算得出，过期是\"惰性\"的：代币过期时不需要运行任何东西。\n\n标准的 ERC-20 函数含义略有变化：\n\n- `balanceOf` 只返回**未过期**的代币。\n- `transfer` / `transferFrom` 只能转移未过期的代币，否则必须回滚或返回 `false`。实现可以优先花费最先到期的代币。\n- 当代币悄悄过期时，`totalSupply` 很难计算，因此规范规定它**应当**返回 `0` 或 `type(uint256).max`。\n\n新增函数：\n\n| 函数 | 用途 |\n| --- | --- |\n| `currentEpoch()` | 最新的纪元 |\n| `epochLength()`, `epochType()` | 纪元的长度和单位 |\n| `validityDuration()` | 代币保持有效的纪元数 |\n| `isEpochExpired(epoch)` | 过期检查 |\n| `balanceOfAtEpoch(epoch, account)` | 某一纪元的余额（已过期则为 0） |\n| `transferAtEpoch` / `transferFromAtEpoch` | 转移指定纪元的代币 |\n\n规范中的例子：纪元 1、2、3 的余额分别为 100、150 和 200，当前纪元为 3，有效期可回溯一个纪元。可用余额为 150 + 200 = 350。\n\n## 示例代码\n\n读取可过期余额（ethers v6）：\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst abi = [\n  \"function balanceOf(address) view returns (uint256)\",\n  \"function currentEpoch() view returns (uint256)\",\n  \"function validityDuration() view returns (uint256)\",\n  \"function balanceOfAtEpoch(uint256 epoch, address account) view returns (uint256)\",\n];\nconst token = new Contract(tokenAddress, abi, new JsonRpcProvider(process.env.RPC_URL));\n\nconst usable = await token.balanceOf(user);           // non-expired only\nconst now: bigint = await token.currentEpoch();\nconst validity: bigint = await token.validityDuration();\n\nfor (let e = now; e \u003e= 0n \u0026\u0026 now - e \u003c= validity; e--) {\n  console.log(`epoch ${e}:`, await token.balanceOfAtEpoch(e, user)); // 0 once expired\n}\nconsole.log(\"usable:\", usable);\n```\n\n## 需要注意\n\n- **状态：Final。**\n- 假定余额只会通过 `Transfer` 事件变化的工具会出错：纪元过期时余额会悄悄减少。`totalSupply` 同样没有意义。\n- DEX 资金池或借贷协议中的可过期代币可能在存入期间过期；大多数 DeFi 集成并没有为此做设计。\n- 跨许多小的纪元桶花费代币可能消耗大量 gas，余额过于碎片化有触及区块 gas 上限的风险。\n- 基于时间的纪元依赖 `block.timestamp`。参考实现改用区块号，部分原因是担心 L2 停机。\n"}}}
