EIPs Explained

ERC-7564 · Draft · ERC · 2023-11-21

ERC-7564: Contract wallet management NFT

A draft interface that moves NFT approvals and transfers into the user's smart contract wallet, letting the wallet enforce its own rules for who may move which NFTs.

What problem does it solve?

With ERC-721, approvals are stored inside each NFT contract. A setApprovalForAll given to a marketplace years ago stays live until you find that collection and revoke it, and the NFT contract decides what an approval means. An externally-owned account has no code, so it cannot add its own limits.

A smart contract wallet (for example one built on ERC-4337) can. ERC-7564 proposes that the wallet itself hold NFT permissions and perform the transfers, so the user's account, not each collection, is the place where approvals are granted, checked and revoked. It is the NFT counterpart of ERC-7204 for fungible tokens.

How it works

The wallet implements IERC7564 and ERC-165. Permissions exist at three levels:

Level Set with Read with
One NFT (asset, tokenId) nftApprove(asset, operator, tokenId) nftGetApproved(asset, operator, tokenId)
All NFTs of one collection nftSetApprovalForOneAll(asset, operator, approved) nftIsApprovedForOneAll(asset, operator)
All NFTs in the wallet nftSetApprovalForAllAll(operator, approved) nftIsApprovedForAllAll(operator)

Matching events NftApproval, NftApprovalForOneAll and NftApprovalForAllAll are emitted.

nftTransfer(asset, to, tokenId) calls the NFT contract's transfer from inside the wallet. If the caller is the wallet itself it proceeds; otherwise the wallet must check the caller's approval first and update it. Optional extras include batch operations, hooks before and after transfers, and an nftReceive function.

Sample code

Core of a wallet-side transfer check (owner auth and ERC-165 omitted):

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

interface IERC721 { function transferFrom(address from, address to, uint256 id) external; }

contract NftWallet {
    mapping(address => mapping(address => mapping(uint256 => bool))) private _one; // asset=>op=>id
    mapping(address => mapping(address => bool)) private _collection;             // asset=>op
    mapping(address => bool) private _all;                                        // op

    function nftTransfer(address asset, address to, uint256 id) external returns (bool) {
        if (msg.sender != address(this)) {
            bool ok = _one[asset][msg.sender][id] || _collection[asset][msg.sender] || _all[msg.sender];
            require(ok, "not approved");
            _one[asset][msg.sender][id] = false; // single-NFT approval is used up
        }
        IERC721(asset).transferFrom(address(this), to, id);
        return true;
    }
}

Things to know

  • Status is Draft. The spec still has TODO placeholders and does not yet state the ERC-165 interface ID.
  • Its Security Considerations section is empty; treat any implementation as unaudited.
  • Approvals you granted directly on NFT contracts (approve / setApprovalForAll) remain in force; this scheme only covers transfers routed through nftTransfer.
  • The spec names transfer() loosely; real ERC-721 contracts expose transferFrom / safeTransferFrom, as used above.

#wallet #account-abstraction #nft #approval

Details

Authors
Xiang (@wenzhenxiang), Ben77 (@ben2077), Mingshi S. (@newnewsms)
Status
Draft
Type
Standards Track / ERC
Created
2023-11-21
Requires

Machine-readable: Markdown · JSON