ERC-1761 Scoped approval interface
Stagnant · NFTs & multi-token · created 2019-02-18
An interface that groups token IDs into "scopes" so operator permissions can be granted to a third party only within that scope. It applies to ID-based tokens such as ERC-721 and ERC-1155.
Why it is needed
In existing token standards, granting approval to a third party (operator) usually hands over permission for all tokens held by the wallet at once. If a user does not thoroughly vet the contract they are approving, they risk losing even their high-value tokens along with the rest. Also, when multiple issuers or departments share a single token contract, there is no standard way to separately manage each one's token ID ranges. ERC-1761 reduces this problem by providing an interface that divides token IDs into arbitrary scopes and lets approval be restricted at the scope level.
What to implement
event ApprovalForScope(address indexed _owner, address indexed _operator, bytes32 indexed _scope, bool _approved);: Emitted when the operator approval status for a specific scope changes.event IdsAddedToScope(uint256 indexed _idStart, uint256 indexed _idEnd, bytes32 indexed _scope);: Emitted when a range of token IDs is added to a scope.event IdsRemovedFromScope(uint256 indexed _idStart, uint256 indexed _idEnd, bytes32 indexed _scope);: Emitted when a range of token IDs is removed from a scope.event ScopeURI(string _value, bytes32 indexed _scope);: Emitted when a scope's metadata URI is set or changed.function scopeCountForId(uint256 _id) public view returns (uint32);: Returns the number of scopes that the given token ID belongs to.function scopeForId(uint256 _id, uint32 _scopeIndex) public view returns (bytes32);: Returns the _scopeIndex-th scope among the scopes that the given token ID belongs to.function scopeUri(bytes32 _scope) public view returns (string memory);: Returns a URI from which the scope's metadata JSON can be fetched.function setApprovalForScope(address _operator, bytes32 _scope, bool _approved) external;: Grants or revokes approval for a third party (operator) to manage the caller's tokens within the specified scope.function isApprovedForScope(address _owner, address _operator, bytes32 _scope) public view returns (bool);: Queries whether a specific owner has approved a specific operator for a specific scope.
In depth
Basic concept of scopes
A scope is an arbitrary group identified by a bytes32 value, grouping together one or more token IDs. According to the source text, a token ID does not belong to any scope by default. Implementers define scopes and add or remove ID ranges via the IdsAddedToScope and IdsRemovedFromScope events. Such a range includes _idStart and _idEnd, where _idStart must be less than or equal to _idEnd. Whether scopes are fixed in number or user-creatable is left up to the implementation rather than specified by the standard.
Approval and query functions
setApprovalForScope(_operator, _scope, _approved) changes operator approval status within the specified scope and must emit an ApprovalForScope event on success. isApprovedForScope(_owner, _operator, _scope) queries whether that owner has approved that operator for that scope. scopeCountForId(_id) returns the number of scopes the given ID belongs to, and scopeForId(_id, _scopeIndex) queries each scope using an index from 0 to scopeCountForId(_id)-1.
Scope metadata URI
scopeUri(_scope) returns a URI in RFC 3986 format, and this URI must point to a JSON document conforming to the 'Scope Metadata JSON Schema'. It may return an empty string for scopes that have no URI. The ScopeURI event fires when a scope's URI is set or changed.
Scope Metadata JSON Schema and localization support
In Scope Metadata JSON, the name field is required and description is optional. Adding a localization property enables multi-language support, requiring three fields: uri (where the client substitutes the literal string {locale} with an actual locale value), default (the locale of the default data), and locales (the list of supported locales, per the Unicode CLDR standard).
ERC-165 identifier and applicable targets
The ERC-165 identifier for this interface is 0x30168307. It is designed to be used with token contracts that have an ID domain, such as ERC-1155 or ERC-721.
Design background
It was originally proposed as an extension of ERC-1155 itself, but during discussion it was decided to split it into a separate interface not tied to any specific token standard. This lets multiple ID-based token standards, such as ERC-721 and ERC-1155, implement scope approval optionally rather than being forced to.
Proposal status
This proposal is in Stagnant status. Written in 2019, it has seen no further progress and may never be changed or adopted going forward.