{"eip":5646,"title":"Token State Fingerprint","description":"Unambiguous token state identifier","authors":["Naim Ashhab (@ashhanai)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2022-09-11","requires":[165],"discussionsTo":"https://ethereum-magicians.org/t/eip-5646-discussion-token-state-fingerprint/10808","repo":"ERCs","label":"ERC-5646","officialUrl":"https://eips.ethereum.org/EIPS/eip-5646","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5646.md","url":"https://eips.huatuo.xyz/eip-5646/","tldr":{"en":"Adds getStateFingerprint(tokenId) so protocols can detect when a mutable NFT's state has changed, without understanding how that token stores its state.","ja":"getStateFingerprint(tokenId) を追加し、プロトコルが、そのトークンが状態をどう保持しているかを理解しなくても、可変 NFT の状態が変わったことを検知できるようにする。","ko":"getStateFingerprint(tokenId)를 추가해, 프로토콜이 해당 토큰이 상태를 어떻게 저장하는지 몰라도 가변 NFT의 상태가 바뀌었는지 감지할 수 있게 한다.","zh":"增加 getStateFingerprint(tokenId)，让协议无需理解某个代币如何存储状态，就能检测可变 NFT 的状态是否发生了变化。"},"tags":["nft","token","mutable","marketplace","interface"],"explainers":{"en":{"lang":"en","tldr":"Adds getStateFingerprint(tokenId) so protocols can detect when a mutable NFT's state has changed, without understanding how that token stores its state.","tags":["nft","token","mutable","marketplace","interface"],"related":[721,1155,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5646/","markdown":"## What problem does it solve?\n\nMany NFTs are not static pictures. An LP position NFT holds amounts that change, a bond NFT matures, a game item gains stats. If a marketplace or lending protocol makes an offer for \"token #42\", the owner could change the token's state (say, withdraw the liquidity) right before accepting the offer, and the counterparty gets something worth much less.\n\nTo protect against that, a protocol needs an identifier for \"token #42 *in this exact state*\". Until now, it had to understand each token's internal fields and hash them itself, which means custom integration work for every new token type.\n\nERC-5646 moves that job into the token: the token itself publishes a fingerprint of its current state.\n\n## How it works\n\nThe token contract implements one view function:\n\n```solidity\nfunction getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n```\n\nThe rules:\n\n- The value **must change** whenever the token's state changes, and **must not change** if the state stays the same.\n- It must cover every property that can change during the token's life. Immutable properties can be left out, because the token id already identifies them.\n- It **may** include computed values (for example whether the token has expired, based on the current timestamp) and the metadata URI.\n- `supportsInterface(0xf5112315)` must return `true` ([ERC-165](/eip-165/)).\n\nA protocol stores the fingerprint when an offer is made and checks it again at execution. If they differ, the token changed in between and the trade is rejected.\n\n## Sample code\n\nA token computing its fingerprint (adapted from the spec's reference implementation):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC5646 {\n    function getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n}\n\ncontract LPPosition is IERC5646 {\n    struct State {\n        address asset1;\n        address asset2;\n        uint256 amount1;\n        uint256 amount2;\n        uint256 fee;         // immutable -\u003e not in fingerprint\n        uint256 expiration;  // fingerprint uses \"expired or not\"\n    }\n    mapping(uint256 =\u003e State) internal states;\n\n    function getStateFingerprint(uint256 tokenId) public view returns (bytes32) {\n        State storage s = states[tokenId];\n        return keccak256(abi.encode(\n            s.asset1, s.asset2, s.amount1, s.amount2,\n            block.timestamp \u003e= s.expiration\n        ));\n    }\n\n    function supportsInterface(bytes4 id) public pure returns (bool) {\n        return id == 0x01ffc9a7 || id == 0xf5112315;\n    }\n}\n```\n\nA marketplace guarding an offer against state changes:\n\n```solidity\nstruct Offer { address collection; uint256 tokenId; bytes32 fingerprint; uint256 price; }\n\nfunction accept(Offer calldata o) external {\n    require(\n        IERC5646(o.collection).getStateFingerprint(o.tokenId) == o.fingerprint,\n        \"token state changed\"\n    );\n    // ... transfer NFT and payment\n}\n```\n\n## Things to know\n\n- **Status: Final.**\n- Fingerprints are only meaningful within one contract. Two different contracts can produce the same value, so always compare them together with the collection address.\n- The safety of the scheme depends entirely on the token implementation. If a mutable field is left out of the hash, the owner can change it without changing the fingerprint.\n- It does not help when a protocol actually needs to *read* specific state properties (for example to value the token); it only tells you \"same or different\".\n"},"ja":{"lang":"ja","tldr":"getStateFingerprint(tokenId) を追加し、プロトコルが、そのトークンが状態をどう保持しているかを理解しなくても、可変 NFT の状態が変わったことを検知できるようにする。","tags":["nft","token","mutable","marketplace","interface"],"related":[721,1155,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5646/","markdown":"## 何を解決するのか\n\n多くの NFT は静止した画像ではありません。LP ポジション NFT は変化する数量を保持し、債券 NFT は満期を迎え、ゲームのアイテムはステータスが上がります。マーケットプレイスやレンディングプロトコルが「トークン #42」に対するオファーを出した場合、オーナーはオファーを受諾する直前にトークンの状態を変更（たとえば流動性を引き出す）でき、相手方は価値がはるかに低いものを受け取ることになります。\n\nこれを防ぐには、プロトコルに「トークン #42 の*この状態そのもの*」を示す識別子が必要です。これまでは、各トークンの内部フィールドを理解して自分でハッシュを計算する必要があり、新しい種類のトークンごとに個別の連携作業が必要でした。\n\nERC-5646 はその仕事をトークン側に移します。トークン自身が現在の状態のフィンガープリントを公開します。\n\n## 仕組み\n\nトークンコントラクトは view 関数を 1 つ実装します。\n\n```solidity\nfunction getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n```\n\nルールは次のとおりです。\n\n- トークンの状態が変わるたびに値は**変わらなければならず**、状態が同じなら**変わってはなりません**。\n- トークンの存続期間中に変わりうるすべてのプロパティを対象に含めなければなりません。不変のプロパティは、トークン ID がすでにそれを識別しているので除外してかまいません。\n- 計算された値（たとえば現在のタイムスタンプに基づくトークンの期限切れかどうか）やメタデータ URI を含めて**もかまいません**。\n- `supportsInterface(0xf5112315)` は `true` を返さなければなりません（[ERC-165](/eip-165/)）。\n\nプロトコルはオファー作成時にフィンガープリントを保存し、実行時に再度確認します。異なっていれば、その間にトークンが変化したということなので、取引は拒否されます。\n\n## サンプルコード\n\nトークンがフィンガープリントを計算する例です（仕様のリファレンス実装を改変）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC5646 {\n    function getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n}\n\ncontract LPPosition is IERC5646 {\n    struct State {\n        address asset1;\n        address asset2;\n        uint256 amount1;\n        uint256 amount2;\n        uint256 fee;         // immutable -\u003e not in fingerprint\n        uint256 expiration;  // fingerprint uses \"expired or not\"\n    }\n    mapping(uint256 =\u003e State) internal states;\n\n    function getStateFingerprint(uint256 tokenId) public view returns (bytes32) {\n        State storage s = states[tokenId];\n        return keccak256(abi.encode(\n            s.asset1, s.asset2, s.amount1, s.amount2,\n            block.timestamp \u003e= s.expiration\n        ));\n    }\n\n    function supportsInterface(bytes4 id) public pure returns (bool) {\n        return id == 0x01ffc9a7 || id == 0xf5112315;\n    }\n}\n```\n\n状態の変化からオファーを守るマーケットプレイス:\n\n```solidity\nstruct Offer { address collection; uint256 tokenId; bytes32 fingerprint; uint256 price; }\n\nfunction accept(Offer calldata o) external {\n    require(\n        IERC5646(o.collection).getStateFingerprint(o.tokenId) == o.fingerprint,\n        \"token state changed\"\n    );\n    // ... transfer NFT and payment\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final。**\n- フィンガープリントは 1 つのコントラクト内でのみ意味を持ちます。異なる 2 つのコントラクトが同じ値を生成することもあるため、必ずコレクションのアドレスと併せて比較してください。\n- この仕組みの安全性は、完全にトークンの実装に依存します。可変のフィールドがハッシュから漏れていれば、オーナーはフィンガープリントを変えずにそれを変更できます。\n- プロトコルが特定の状態プロパティを実際に*読み取る*必要がある場合（たとえばトークンを評価するため）には役立ちません。わかるのは「同じか違うか」だけです。\n"},"ko":{"lang":"ko","tldr":"getStateFingerprint(tokenId)를 추가해, 프로토콜이 해당 토큰이 상태를 어떻게 저장하는지 몰라도 가변 NFT의 상태가 바뀌었는지 감지할 수 있게 한다.","tags":["nft","token","mutable","marketplace","interface"],"related":[721,1155,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5646/","markdown":"## 어떤 문제를 해결하나요?\n\n많은 NFT는 정적인 그림이 아닙니다. LP 포지션 NFT는 변하는 수량을 담고 있고, 채권 NFT는 만기가 되며, 게임 아이템은 능력치가 오릅니다. 마켓플레이스나 대출 프로토콜이 \"토큰 #42\"에 대한 오퍼를 내면, 소유자는 오퍼를 수락하기 직전에 토큰의 상태를 바꿀 수 있고(예: 유동성 인출), 상대방은 훨씬 가치가 낮은 것을 받게 됩니다.\n\n이를 막으려면 프로토콜에 \"토큰 #42의 *바로 이 상태*\"를 가리키는 식별자가 필요합니다. 지금까지는 각 토큰의 내부 필드를 이해하고 직접 해시를 계산해야 했으므로, 새로운 토큰 유형마다 맞춤 연동 작업이 필요했습니다.\n\nERC-5646은 그 일을 토큰 안으로 옮깁니다. 토큰 자체가 현재 상태의 핑거프린트를 공개합니다.\n\n## 어떻게 동작하나요?\n\n토큰 컨트랙트는 view 함수 하나를 구현합니다.\n\n```solidity\nfunction getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n```\n\n규칙은 다음과 같습니다.\n\n- 토큰의 상태가 바뀔 때마다 값이 **반드시 바뀌어야** 하고, 상태가 그대로면 **바뀌어서는 안 됩니다**.\n- 토큰의 수명 동안 바뀔 수 있는 모든 속성을 포함해야 합니다. 변하지 않는 속성은 토큰 ID가 이미 식별하므로 빼도 됩니다.\n- 계산된 값(예: 현재 타임스탬프를 기준으로 한 토큰의 만료 여부)과 메타데이터 URI를 포함**할 수 있습니다**.\n- `supportsInterface(0xf5112315)`는 `true`를 반환해야 합니다([ERC-165](/eip-165/)).\n\n프로토콜은 오퍼를 낼 때 핑거프린트를 저장하고 실행 시 다시 확인합니다. 서로 다르면 그 사이에 토큰이 바뀐 것이므로 거래가 거부됩니다.\n\n## 샘플 코드\n\n토큰이 핑거프린트를 계산하는 예시입니다(사양의 레퍼런스 구현을 변형).\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC5646 {\n    function getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n}\n\ncontract LPPosition is IERC5646 {\n    struct State {\n        address asset1;\n        address asset2;\n        uint256 amount1;\n        uint256 amount2;\n        uint256 fee;         // immutable -\u003e not in fingerprint\n        uint256 expiration;  // fingerprint uses \"expired or not\"\n    }\n    mapping(uint256 =\u003e State) internal states;\n\n    function getStateFingerprint(uint256 tokenId) public view returns (bytes32) {\n        State storage s = states[tokenId];\n        return keccak256(abi.encode(\n            s.asset1, s.asset2, s.amount1, s.amount2,\n            block.timestamp \u003e= s.expiration\n        ));\n    }\n\n    function supportsInterface(bytes4 id) public pure returns (bool) {\n        return id == 0x01ffc9a7 || id == 0xf5112315;\n    }\n}\n```\n\n상태 변경으로부터 오퍼를 보호하는 마켓플레이스입니다.\n\n```solidity\nstruct Offer { address collection; uint256 tokenId; bytes32 fingerprint; uint256 price; }\n\nfunction accept(Offer calldata o) external {\n    require(\n        IERC5646(o.collection).getStateFingerprint(o.tokenId) == o.fingerprint,\n        \"token state changed\"\n    );\n    // ... transfer NFT and payment\n}\n```\n\n## 알아둘 점\n\n- **상태: Final.**\n- 핑거프린트는 하나의 컨트랙트 안에서만 의미가 있습니다. 서로 다른 두 컨트랙트가 같은 값을 만들 수 있으므로 항상 컬렉션 주소와 함께 비교하세요.\n- 이 방식의 안전성은 전적으로 토큰 구현에 달려 있습니다. 가변 필드가 해시에서 빠져 있으면 소유자는 핑거프린트를 바꾸지 않고 그 필드를 바꿀 수 있습니다.\n- 프로토콜이 특정 상태 속성을 실제로 *읽어야* 할 때(예: 토큰의 가치를 평가하기 위해)는 도움이 되지 않습니다. 알려주는 것은 \"같은지 다른지\"뿐입니다.\n"},"zh":{"lang":"zh","tldr":"增加 getStateFingerprint(tokenId)，让协议无需理解某个代币如何存储状态，就能检测可变 NFT 的状态是否发生了变化。","tags":["nft","token","mutable","marketplace","interface"],"related":[721,1155,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5646/","markdown":"## 它解决什么问题？\n\n许多 NFT 并不是静态图片。LP 头寸 NFT 持有会变化的数量，债券 NFT 会到期，游戏道具会提升属性。如果市场或借贷协议对\"代币 #42\"发出报价，所有者可以在接受报价之前改变代币的状态（比如提取流动性），对手方最终得到的东西价值要低得多。\n\n为防止这种情况，协议需要一个标识符来表示\"处于*这个确切状态*的代币 #42\"。此前，协议必须理解每种代币的内部字段并自行计算哈希，这意味着每出现一种新代币类型就要做定制集成。\n\nERC-5646 把这项工作移到代币内部：由代币自己发布其当前状态的指纹。\n\n## 它如何运作\n\n代币合约实现一个 view 函数：\n\n```solidity\nfunction getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n```\n\n规则如下：\n\n- 只要代币的状态发生变化，该值就**必须改变**；状态不变，则**不得改变**。\n- 它必须涵盖代币生命周期中可能变化的每一项属性。不可变的属性可以省略，因为 token id 已经标识了它们。\n- 它**可以**包含计算得出的值（例如根据当前时间戳判断代币是否已过期）以及元数据 URI。\n- `supportsInterface(0xf5112315)` 必须返回 `true`（[ERC-165](/eip-165/)）。\n\n协议在发出报价时保存指纹，并在执行时再次检查。如果两者不同，说明代币在此期间发生了变化，交易将被拒绝。\n\n## 示例代码\n\n一个计算自身指纹的代币（改编自规范的参考实现）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ninterface IERC5646 {\n    function getStateFingerprint(uint256 tokenId) external view returns (bytes32);\n}\n\ncontract LPPosition is IERC5646 {\n    struct State {\n        address asset1;\n        address asset2;\n        uint256 amount1;\n        uint256 amount2;\n        uint256 fee;         // immutable -\u003e not in fingerprint\n        uint256 expiration;  // fingerprint uses \"expired or not\"\n    }\n    mapping(uint256 =\u003e State) internal states;\n\n    function getStateFingerprint(uint256 tokenId) public view returns (bytes32) {\n        State storage s = states[tokenId];\n        return keccak256(abi.encode(\n            s.asset1, s.asset2, s.amount1, s.amount2,\n            block.timestamp \u003e= s.expiration\n        ));\n    }\n\n    function supportsInterface(bytes4 id) public pure returns (bool) {\n        return id == 0x01ffc9a7 || id == 0xf5112315;\n    }\n}\n```\n\n一个保护报价不受状态变化影响的市场：\n\n```solidity\nstruct Offer { address collection; uint256 tokenId; bytes32 fingerprint; uint256 price; }\n\nfunction accept(Offer calldata o) external {\n    require(\n        IERC5646(o.collection).getStateFingerprint(o.tokenId) == o.fingerprint,\n        \"token state changed\"\n    );\n    // ... transfer NFT and payment\n}\n```\n\n## 需要注意\n\n- **状态：Final。**\n- 指纹只在单个合约内才有意义。两个不同的合约可能产生相同的值，因此务必连同合集地址一起比较。\n- 该方案的安全性完全取决于代币的实现。如果某个可变字段没有纳入哈希，所有者就可以修改它而不改变指纹。\n- 当协议确实需要*读取*特定的状态属性（例如为代币估值）时，它帮不上忙；它只告诉你\"相同还是不同\"。\n"}}}
