---
eip: 5216
label: ERC-5216
title: ERC-1155 Allowance Extension
status: Last Call
type: Standards Track
category: ERC
created: 2022-07-11
requires: 20, 165, 1155
official: https://eips.ethereum.org/EIPS/eip-5216
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5216.md
canonical: https://eips.huatuo.xyz/eip-5216/
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]
---

# ERC-5216: ERC-1155 Allowance Extension

> Extension for ERC-1155 secure approvals

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

## What problem does it solve?

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

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

## How it works

The contract implements `IERC5216` on top of ERC-1155:

```solidity
event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);
function approve(address operator, uint256 id, uint256 amount) external;
function allowance(address account, address operator, uint256 id) external view returns (uint256);
```

- `approve` sets (not adds to) the operator's allowance for one id and emits `Approval`. The operator cannot be the caller.
- `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).
- `safeBatchTransferFrom` must check the allowance for every id in the batch.
- `supportsInterface(0x1be07d74)` returns `true` ([ERC-165](/eip-165/)).

## Sample code

Core logic layered on OpenZeppelin's ERC-1155 (v5), for illustration:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract ERC1155Allowance is ERC1155 {
    event Approval(address indexed account, address indexed operator, uint256 id, uint256 amount);

    mapping(address => mapping(address => mapping(uint256 => uint256))) private _allowances;

    constructor() ERC1155("https://example.invalid/{id}.json") {}

    function approve(address operator, uint256 id, uint256 amount) external {
        require(operator != msg.sender, "self approval");
        _allowances[msg.sender][operator][id] = amount;
        emit Approval(msg.sender, operator, id, amount);
    }

    function allowance(address account, address operator, uint256 id) public view returns (uint256) {
        return _allowances[account][operator][id];
    }

    function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data)
        public override
    {
        if (from != msg.sender && !isApprovedForAll(from, msg.sender)) {
            uint256 a = _allowances[from][msg.sender][id];
            require(a >= value, "insufficient allowance");
            _allowances[from][msg.sender][id] = a - value;
        }
        _safeTransferFrom(from, to, id, value, data);
    }

    function supportsInterface(bytes4 iid) public view override returns (bool) {
        return iid == 0x1be07d74 || super.supportsInterface(iid);
    }
    // safeBatchTransferFrom must apply the same check per id (omitted)
}
```

## Things to know

- Status: **Last Call** (deadline in 2022, never moved to Final). The interface may still be considered unsettled.
- Marketplaces only benefit if they actually request per-id allowances; many still ask for `setApprovalForAll`.
- 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.
- `setApprovalForAll` still overrides everything. Check `isApprovedForAll` when auditing what an operator can move.


---

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