{"eip":5216,"title":"ERC-1155 Allowance Extension","description":"Extension for ERC-1155 secure approvals","authors":["Iván Mañús (@ivanmmurciaua)","Juan Carlos Cantó (@EscuelaCryptoES)"],"status":"Last Call","type":"Standards Track","category":"ERC","created":"2022-07-11","requires":[20,165,1155],"discussionsTo":"https://ethereum-magicians.org/t/eip-erc1155-approval-by-amount/9898","repo":"ERCs","label":"ERC-5216","officialUrl":"https://eips.ethereum.org/EIPS/eip-5216","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5216.md","url":"https://eips.huatuo.xyz/eip-5216/","tldr":{"en":"Adds ERC-20-style approve(operator, id, amount) and allowance() to ERC-1155, so you can let a marketplace move a limited number of one token id instead of everything.","ja":"ERC-1155 に ERC-20 風の approve(operator, id, amount) と allowance() を追加し、マーケットプレイスにすべてではなく、1 つのトークン ID の限られた数量だけを動かす権限を与えられるようにする。","ko":"ERC-1155에 ERC-20 방식의 approve(operator, id, amount)와 allowance()를 추가해, 마켓플레이스가 모든 토큰이 아니라 하나의 토큰 ID 중 제한된 수량만 옮기도록 허용할 수 있게 한다.","zh":"为 ERC-1155 增加 ERC-20 风格的 approve(operator, id, amount) 和 allowance()，让你可以只允许市场转移某个 token id 的有限数量，而不是全部代币。"},"tags":["erc-1155","approvals","allowance","nft","security"],"explainers":{"en":{"lang":"en","tldr":"Adds ERC-20-style approve(operator, id, amount) and allowance() to ERC-1155, so you can let a marketplace move a limited number of one token id instead of everything.","tags":["erc-1155","approvals","allowance","nft","security"],"related":[1155,20,721,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5216/","markdown":"## What problem does it solve?\n\n[ERC-1155](/eip-1155/) has only one approval mechanism: `setApprovalForAll(operator, true)`, which lets the operator move **every** token you hold in that contract, of every id, in any amount. To list a single item on a marketplace you must give the marketplace unlimited access to the whole collection. A bug or a compromised operator can then drain everything.\n\nERC-5216 borrows the allowance model from [ERC-20](/eip-20/) so owners can approve exactly what is needed: a given `amount` of a given `id`.\n\n## How it works\n\nThe contract implements `IERC5216` on top of ERC-1155:\n\n```solidity\nevent Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\nfunction approve(address operator, uint256 id, uint256 amount) external;\nfunction allowance(address account, address operator, uint256 id) external view returns (uint256);\n```\n\n- `approve` sets (not adds to) the operator's allowance for one id and emits `Approval`. The operator cannot be the caller.\n- `safeTransferFrom` must succeed when the caller has a sufficient allowance for that id, and must **deduct** the transferred amount, unless the caller is approved via `setApprovalForAll` (which still means unlimited).\n- `safeBatchTransferFrom` must check the allowance for every id in the batch.\n- `supportsInterface(0x1be07d74)` returns `true` ([ERC-165](/eip-165/)).\n\n## Sample code\n\nCore logic layered on OpenZeppelin's ERC-1155 (v5), for illustration:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport {ERC1155} from \"@openzeppelin/contracts/token/ERC1155/ERC1155.sol\";\n\ncontract ERC1155Allowance is ERC1155 {\n    event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\n\n    mapping(address =\u003e mapping(address =\u003e mapping(uint256 =\u003e uint256))) private _allowances;\n\n    constructor() ERC1155(\"https://example.invalid/{id}.json\") {}\n\n    function approve(address operator, uint256 id, uint256 amount) external {\n        require(operator != msg.sender, \"self approval\");\n        _allowances[msg.sender][operator][id] = amount;\n        emit Approval(msg.sender, operator, id, amount);\n    }\n\n    function allowance(address account, address operator, uint256 id) public view returns (uint256) {\n        return _allowances[account][operator][id];\n    }\n\n    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data)\n        public override\n    {\n        if (from != msg.sender \u0026\u0026 !isApprovedForAll(from, msg.sender)) {\n            uint256 a = _allowances[from][msg.sender][id];\n            require(a \u003e= value, \"insufficient allowance\");\n            _allowances[from][msg.sender][id] = a - value;\n        }\n        _safeTransferFrom(from, to, id, value, data);\n    }\n\n    function supportsInterface(bytes4 iid) public view override returns (bool) {\n        return iid == 0x1be07d74 || super.supportsInterface(iid);\n    }\n    // safeBatchTransferFrom must apply the same check per id (omitted)\n}\n```\n\n## Things to know\n\n- Status: **Last Call** (deadline in 2022, never moved to Final). The interface may still be considered unsettled.\n- Marketplaces only benefit if they actually request per-id allowances; many still ask for `setApprovalForAll`.\n- Like ERC-20, changing a non-zero allowance to another non-zero value can be front-run. Set it to 0 first, and revoke unused allowances.\n- `setApprovalForAll` still overrides everything. Check `isApprovedForAll` when auditing what an operator can move.\n"},"ja":{"lang":"ja","tldr":"ERC-1155 に ERC-20 風の approve(operator, id, amount) と allowance() を追加し、マーケットプレイスにすべてではなく、1 つのトークン ID の限られた数量だけを動かす権限を与えられるようにする。","tags":["erc-1155","approvals","allowance","nft","security"],"related":[1155,20,721,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5216/","markdown":"## 何を解決するのか\n\n[ERC-1155](/eip-1155/) の承認の仕組みは `setApprovalForAll(operator, true)` だけです。これは、そのコントラクトで保有する**すべて**のトークン（全 ID、任意の数量）をオペレーターが動かせるようにします。マーケットプレイスに 1 つのアイテムを出品するだけでも、コレクション全体への無制限のアクセスを与えなければなりません。バグや侵害されたオペレーターがいれば、すべてを抜き取られかねません。\n\nERC-5216 は [ERC-20](/eip-20/) のアローワンスのモデルを借りて、オーナーが必要なものだけ、つまり特定の `id` の特定の `amount` だけを承認できるようにします。\n\n## 仕組み\n\nコントラクトは ERC-1155 の上に `IERC5216` を実装します。\n\n```solidity\nevent Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\nfunction approve(address operator, uint256 id, uint256 amount) external;\nfunction allowance(address account, address operator, uint256 id) external view returns (uint256);\n```\n\n- `approve` は、1 つの ID に対するオペレーターのアローワンスを（加算ではなく）設定し、`Approval` を発行します。オペレーターを呼び出し元自身にすることはできません。\n- `safeTransferFrom` は、呼び出し元がその ID について十分なアローワンスを持っていれば成功しなければならず、転送した量を**差し引か**なければなりません。ただし、呼び出し元が `setApprovalForAll` で承認されている場合は例外で、その場合は引き続き無制限を意味します。\n- `safeBatchTransferFrom` は、バッチ内のすべての ID についてアローワンスを確認しなければなりません。\n- `supportsInterface(0x1be07d74)` は `true` を返します（[ERC-165](/eip-165/)）。\n\n## サンプルコード\n\nOpenZeppelin の ERC-1155（v5）の上に重ねたコアロジックの例です:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport {ERC1155} from \"@openzeppelin/contracts/token/ERC1155/ERC1155.sol\";\n\ncontract ERC1155Allowance is ERC1155 {\n    event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\n\n    mapping(address =\u003e mapping(address =\u003e mapping(uint256 =\u003e uint256))) private _allowances;\n\n    constructor() ERC1155(\"https://example.invalid/{id}.json\") {}\n\n    function approve(address operator, uint256 id, uint256 amount) external {\n        require(operator != msg.sender, \"self approval\");\n        _allowances[msg.sender][operator][id] = amount;\n        emit Approval(msg.sender, operator, id, amount);\n    }\n\n    function allowance(address account, address operator, uint256 id) public view returns (uint256) {\n        return _allowances[account][operator][id];\n    }\n\n    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data)\n        public override\n    {\n        if (from != msg.sender \u0026\u0026 !isApprovedForAll(from, msg.sender)) {\n            uint256 a = _allowances[from][msg.sender][id];\n            require(a \u003e= value, \"insufficient allowance\");\n            _allowances[from][msg.sender][id] = a - value;\n        }\n        _safeTransferFrom(from, to, id, value, data);\n    }\n\n    function supportsInterface(bytes4 iid) public view override returns (bool) {\n        return iid == 0x1be07d74 || super.supportsInterface(iid);\n    }\n    // safeBatchTransferFrom must apply the same check per id (omitted)\n}\n```\n\n## 知っておくべきこと\n\n- ステータス: **Last Call**（期限は 2022 年で、Final には進みませんでした）。インターフェースはまだ確定していないと見なされる可能性があります。\n- マーケットプレイスが ID ごとのアローワンスを実際に要求しなければ、恩恵はありません。多くは今も `setApprovalForAll` を求めます。\n- ERC-20 と同様に、0 以外のアローワンスを別の 0 以外の値に変更する操作はフロントランされる可能性があります。先に 0 に設定し、使っていないアローワンスは取り消してください。\n- `setApprovalForAll` は依然としてすべてに優先します。オペレーターが何を動かせるかを監査するときは、`isApprovedForAll` を確認してください。\n"},"ko":{"lang":"ko","tldr":"ERC-1155에 ERC-20 방식의 approve(operator, id, amount)와 allowance()를 추가해, 마켓플레이스가 모든 토큰이 아니라 하나의 토큰 ID 중 제한된 수량만 옮기도록 허용할 수 있게 한다.","tags":["erc-1155","approvals","allowance","nft","security"],"related":[1155,20,721,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5216/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-1155](/eip-1155/)의 승인 메커니즘은 `setApprovalForAll(operator, true)` 하나뿐입니다. 이는 오퍼레이터가 그 컨트랙트에서 보유한 **모든** 토큰(모든 ID, 모든 수량)을 옮길 수 있게 합니다. 마켓플레이스에 아이템 하나를 올리려 해도 컬렉션 전체에 대한 무제한 접근 권한을 줘야 합니다. 버그나 탈취된 오퍼레이터가 있으면 전부 털릴 수 있습니다.\n\nERC-5216은 [ERC-20](/eip-20/)의 allowance 모델을 가져와, 소유자가 딱 필요한 만큼, 즉 특정 `id`의 특정 `amount`만 승인할 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n컨트랙트는 ERC-1155 위에 `IERC5216`을 구현합니다.\n\n```solidity\nevent Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\nfunction approve(address operator, uint256 id, uint256 amount) external;\nfunction allowance(address account, address operator, uint256 id) external view returns (uint256);\n```\n\n- `approve`는 하나의 id에 대한 오퍼레이터의 allowance를 (더하는 것이 아니라) 설정하고 `Approval`을 발생시킵니다. 오퍼레이터가 호출자 자신일 수는 없습니다.\n- `safeTransferFrom`은 호출자가 해당 id에 대해 충분한 allowance를 가진 경우 성공해야 하며, 전송한 수량을 **차감**해야 합니다. 다만 호출자가 `setApprovalForAll`로 승인된 경우는 예외이며, 이 경우는 여전히 무제한을 뜻합니다.\n- `safeBatchTransferFrom`은 배치에 있는 모든 id의 allowance를 확인해야 합니다.\n- `supportsInterface(0x1be07d74)`는 `true`를 반환합니다([ERC-165](/eip-165/)).\n\n## 샘플 코드\n\nOpenZeppelin의 ERC-1155(v5) 위에 얹은 핵심 로직으로, 설명용입니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport {ERC1155} from \"@openzeppelin/contracts/token/ERC1155/ERC1155.sol\";\n\ncontract ERC1155Allowance is ERC1155 {\n    event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\n\n    mapping(address =\u003e mapping(address =\u003e mapping(uint256 =\u003e uint256))) private _allowances;\n\n    constructor() ERC1155(\"https://example.invalid/{id}.json\") {}\n\n    function approve(address operator, uint256 id, uint256 amount) external {\n        require(operator != msg.sender, \"self approval\");\n        _allowances[msg.sender][operator][id] = amount;\n        emit Approval(msg.sender, operator, id, amount);\n    }\n\n    function allowance(address account, address operator, uint256 id) public view returns (uint256) {\n        return _allowances[account][operator][id];\n    }\n\n    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data)\n        public override\n    {\n        if (from != msg.sender \u0026\u0026 !isApprovedForAll(from, msg.sender)) {\n            uint256 a = _allowances[from][msg.sender][id];\n            require(a \u003e= value, \"insufficient allowance\");\n            _allowances[from][msg.sender][id] = a - value;\n        }\n        _safeTransferFrom(from, to, id, value, data);\n    }\n\n    function supportsInterface(bytes4 iid) public view override returns (bool) {\n        return iid == 0x1be07d74 || super.supportsInterface(iid);\n    }\n    // safeBatchTransferFrom must apply the same check per id (omitted)\n}\n```\n\n## 알아둘 점\n\n- 상태: **Last Call**(마감일은 2022년이었고 Final로 넘어가지 않았습니다). 인터페이스는 아직 확정되지 않은 것으로 볼 수 있습니다.\n- 마켓플레이스가 실제로 id별 allowance를 요청해야만 이점이 있습니다. 많은 곳이 여전히 `setApprovalForAll`을 요구합니다.\n- ERC-20과 마찬가지로, 0이 아닌 allowance를 다른 0이 아닌 값으로 바꾸면 프런트러닝당할 수 있습니다. 먼저 0으로 설정하고, 쓰지 않는 allowance는 철회하세요.\n- `setApprovalForAll`은 여전히 모든 것을 덮어씁니다. 오퍼레이터가 무엇을 옮길 수 있는지 감사할 때는 `isApprovedForAll`을 확인하세요.\n"},"zh":{"lang":"zh","tldr":"为 ERC-1155 增加 ERC-20 风格的 approve(operator, id, amount) 和 allowance()，让你可以只允许市场转移某个 token id 的有限数量，而不是全部代币。","tags":["erc-1155","approvals","allowance","nft","security"],"related":[1155,20,721,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5216/","markdown":"## 它解决什么问题？\n\n[ERC-1155](/eip-1155/) 只有一种授权机制：`setApprovalForAll(operator, true)`，它让操作者可以转移你在该合约中持有的**所有**代币，无论 id 是什么、数量多少。要在市场上架一件物品，你必须把整个合集的无限访问权限交给市场。一旦出现漏洞或操作者被攻破，你的全部资产都可能被转空。\n\nERC-5216 借用了 [ERC-20](/eip-20/) 的额度模型，让所有者只授权所需的部分：某个 `id` 的指定 `amount`。\n\n## 它如何运作\n\n合约在 ERC-1155 之上实现 `IERC5216`：\n\n```solidity\nevent Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\nfunction approve(address operator, uint256 id, uint256 amount) external;\nfunction allowance(address account, address operator, uint256 id) external view returns (uint256);\n```\n\n- `approve` 为某一个 id 设置（而非累加）操作者的额度并触发 `Approval`。操作者不能是调用者本人。\n- 当调用者对该 id 拥有足够额度时，`safeTransferFrom` 必须成功，并且必须**扣减**已转移的数量；通过 `setApprovalForAll` 获得授权的调用者除外（这仍然意味着无限额度）。\n- `safeBatchTransferFrom` 必须检查批次中每个 id 的额度。\n- `supportsInterface(0x1be07d74)` 返回 `true`（[ERC-165](/eip-165/)）。\n\n## 示例代码\n\n基于 OpenZeppelin 的 ERC-1155（v5）实现的核心逻辑，仅作演示：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nimport {ERC1155} from \"@openzeppelin/contracts/token/ERC1155/ERC1155.sol\";\n\ncontract ERC1155Allowance is ERC1155 {\n    event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);\n\n    mapping(address =\u003e mapping(address =\u003e mapping(uint256 =\u003e uint256))) private _allowances;\n\n    constructor() ERC1155(\"https://example.invalid/{id}.json\") {}\n\n    function approve(address operator, uint256 id, uint256 amount) external {\n        require(operator != msg.sender, \"self approval\");\n        _allowances[msg.sender][operator][id] = amount;\n        emit Approval(msg.sender, operator, id, amount);\n    }\n\n    function allowance(address account, address operator, uint256 id) public view returns (uint256) {\n        return _allowances[account][operator][id];\n    }\n\n    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data)\n        public override\n    {\n        if (from != msg.sender \u0026\u0026 !isApprovedForAll(from, msg.sender)) {\n            uint256 a = _allowances[from][msg.sender][id];\n            require(a \u003e= value, \"insufficient allowance\");\n            _allowances[from][msg.sender][id] = a - value;\n        }\n        _safeTransferFrom(from, to, id, value, data);\n    }\n\n    function supportsInterface(bytes4 iid) public view override returns (bool) {\n        return iid == 0x1be07d74 || super.supportsInterface(iid);\n    }\n    // safeBatchTransferFrom must apply the same check per id (omitted)\n}\n```\n\n## 需要注意\n\n- 状态：**Last Call**（截止日期在 2022 年，从未进入 Final）。该接口可能仍被视为尚未定型。\n- 只有当市场真正请求按 id 授权额度时才有好处；许多市场仍然要求 `setApprovalForAll`。\n- 与 ERC-20 一样，把非零额度改为另一个非零值可能被抢跑。请先设为 0，并撤销未使用的额度。\n- `setApprovalForAll` 仍然凌驾于一切之上。审计操作者能转移什么时，请检查 `isApprovedForAll`。\n"}},"requiredBy":[7604]}
