EIPs Explained

ERC-1761 · Stagnant · ERC · 2019-02-18

ERC-1761: Scoped Approval Interface

Adds scoped approvals to multi-ID token contracts: owners approve an operator for a named group of token IDs instead of everything they hold, limiting the damage if that operator misbehaves.

What problem does it solve?

ERC-721 and ERC-1155 offer setApprovalForAll, an all-or-nothing switch. Approving a marketplace or game contract gives it control over every token you hold in that contract. When one ERC-1155 contract holds items from many games or of very different value, that is far more access than any single app needs.

ERC-1761 lets the token contract group IDs into scopes, so a user can approve an operator for one scope only. Examples from the spec: one scope per regional office of a vehicle fleet, one per game developer sharing an ERC-1155 contract, or separate scopes for low-value and high-value items.

How it works

A scope is a bytes32 identifier covering one or more token IDs; an ID can belong to several scopes. The interface (ERC-165 ID 0x30168307) provides:

Function / event Purpose
setApprovalForScope(operator, scope, approved) Approve or revoke an operator for one scope. Emits ApprovalForScope.
isApprovedForScope(owner, operator, scope) Check an approval.
scopeCountForId(id) / scopeForId(id, index) Find which scopes contain a token ID.
scopeUri(scope) URI of a JSON metadata file describing the scope.
IdsAddedToScope / IdsRemovedFromScope Emitted when inclusive ID ranges join or leave a scope.
ScopeURI Emitted when a scope's metadata URI changes.

How scopes are created and managed is deliberately left to each implementation. A contract might offer a fixed set or assign scopes by token type.

Scope metadata JSON must include a name and should include a description, so wallets can show users what they are approving. An optional localization block points to translated versions.

Sample code

Checking scoped approval inside an ERC-1155 transfer (simplified):

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

abstract contract ScopedApproval1155 {
    mapping(address => mapping(address => mapping(bytes32 => bool))) private scopeApproval;
    mapping(uint256 => bytes32) public scopeOf; // one scope per ID, for simplicity

    event ApprovalForScope(address indexed owner, address indexed operator, bytes32 indexed scope, bool approved);

    function setApprovalForScope(address operator, bytes32 scope, bool approved) external {
        scopeApproval[msg.sender][operator][scope] = approved;
        emit ApprovalForScope(msg.sender, operator, scope, approved);
    }

    function isApprovedForScope(address owner, address operator, bytes32 scope) public view returns (bool) {
        return scopeApproval[owner][operator][scope];
    }

    function _checkOperator(address from, uint256 id) internal view {
        require(
            from == msg.sender || isApprovedForScope(from, msg.sender, scopeOf[id]),
            "not approved for this scope"
        );
    }
}

Example scope metadata:

{
  "name": "Common items",
  "description": "Low-value consumables that trading apps may move on your behalf."
}

Things to know

  • Status is Stagnant. It began as a proposed extension to ERC-1155 and was split out after community discussion.
  • Scoped approval only helps if wallets and marketplaces use it. Most tooling still asks for setApprovalForAll.
  • Decide how scoped approvals interact with setApprovalForAll. The spec does not say whether a global approval should override scopes.
  • Moving IDs between scopes changes what existing approvals cover, so emit the range events and let users review their approvals.

#approval #nft #multi-token #security #erc

Details

Authors
Witek Radomski <[email protected]>, Andrew Cooke <[email protected]>, James Therien <[email protected]>, Eric Binet <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2019-02-18
Requires

Machine-readable: Markdown · JSON