ERC-6464 · Stagnant · ERC · 2023-02-02
ERC-6464: Multi-operator, per-token ERC-721 approvals.
A stagnant ERC-721 extension that lets owners approve several operators for one specific token, instead of handing a marketplace setApprovalForAll over their whole collection.
What problem does it solve?
ERC-721 offers two ways to let someone else move your NFT:
approve(operator, tokenId): exactly one operator per token.setApprovalForAll(operator, true): an operator for every token you own in that collection.
If you want to list one NFT on several marketplaces at once, the single-slot approve is not enough, so in practice everyone uses setApprovalForAll. That breaks the principle of least privilege: a phishing site that tricks you into signing a zero-price sell order can have a legitimate marketplace contract drain the whole collection.
ERC-6464 adds explicit, per-token approvals for multiple operators, plus cheap ways to revoke them.
How it works
IERC6464 (on top of ERC-721 and ERC-165) adds:
| Function / event | Purpose |
|---|---|
setExplicitApproval(operator, tokenId, approved) |
Grant or revoke one operator for one token |
setExplicitApproval(operator, tokenIds[], approved) |
Same, for a list of tokens |
revokeAllExplicitApprovals() |
Drop every explicit approval the caller ever granted |
revokeAllExplicitApprovals(tokenId) |
Drop all explicit approvals on one token |
isExplicitlyApprovedFor(operator, tokenId) |
Query |
ExplicitApprovalFor, AllExplicitApprovalsRevoked |
Events for indexers |
Explicit approvals must be cleared automatically when the token is transferred, and they never change the standard ERC-721 approval getters.
A second, optional interface, IERC6464AnyApproval, adds isApprovedFor(operator, tokenId), which returns true if the operator is approved by any mechanism (explicit, getApproved, or isApprovedForAll). Marketplaces can make one call instead of checking several.
The spec suggests implementing the "revoke all" functions with nonces, so revocation is a single storage write rather than a loop.
Sample code
Nonce-based storage that makes bulk revocation O(1) (sketch):
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;
abstract contract ExplicitApprovals {
event ExplicitApprovalFor(address indexed operator, uint256 indexed tokenId, bool approved);
event AllExplicitApprovalsRevoked(address indexed owner);
event AllExplicitApprovalsRevoked(address indexed owner, uint256 indexed tokenId);
mapping(address => uint256) private ownerNonce;
mapping(uint256 => uint256) private tokenNonce;
// owner => ownerNonce => tokenId => tokenNonce => operator => approved
mapping(address => mapping(uint256 => mapping(uint256 => mapping(uint256 => mapping(address => bool))))) private ok;
function _ownerOf(uint256 tokenId) internal view virtual returns (address);
function setExplicitApproval(address op, uint256 tokenId, bool approved) public {
address owner = _ownerOf(tokenId);
require(msg.sender == owner, "not owner"); // spec also allows owner's operators
ok[owner][ownerNonce[owner]][tokenId][tokenNonce[tokenId]][op] = approved;
emit ExplicitApprovalFor(op, tokenId, approved);
}
function isExplicitlyApprovedFor(address op, uint256 tokenId) public view returns (bool) {
address owner = _ownerOf(tokenId);
return ok[owner][ownerNonce[owner]][tokenId][tokenNonce[tokenId]][op];
}
function revokeAllExplicitApprovals() external {
ownerNonce[msg.sender]++;
emit AllExplicitApprovalsRevoked(msg.sender);
}
// call from the transfer hook so approvals die with the old owner
function _clearOnTransfer(address from, uint256 tokenId) internal {
tokenNonce[tokenId]++;
emit AllExplicitApprovalsRevoked(from, tokenId);
}
}
Things to know
- Status is Stagnant. The draft still contains TODOs: the ERC-165 interface ID is "TBD", the security section is unfinished, and no reference implementation is linked.
- Off-chain indexers should still treat an operator as approved if a standard
ApprovalorApprovalForAllis active, even when anExplicitApprovalFor(..., false)is seen. - ERC-1155 compatibility is explicitly a non-goal, though the authors note the idea applies to 1155 token types too.
- Until something like this is widely adopted, the practical defence remains revoking unused
setApprovalForAllgrants and being careful with marketplace signatures.