ERC-721 Approve Module
Manages ERC-721 token approvals and operator status
- Provides internal functions for ERC-721 token approvals and operator management.
- Utilizes the diamond storage pattern (EIP-8042) for shared state.
- No external dependencies, promoting composability within a diamond.
- Emits
ApprovalandApprovalForAllevents upon successful state changes.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for managing ERC-721 token approvals and operator status within a diamond. Facets can import this module to interact with shared ERC-721 storage, ensuring consistent state management across the diamond. Changes to approvals and operator statuses are immediately visible to all facets accessing the same diamond storage.
Storage
ERC721Storage
storage-location: erc8042:erc721
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc721")) |
Functions
approve
Approves another address to transfer the given token ID.
Parameters:
| Property | Type | Description |
|---|---|---|
_to | address | The address to be approved. |
_tokenId | uint256 | The token ID to approve. |
getStorage
Returns a pointer to the ERC-721 storage struct. Uses inline assembly to access the storage slot defined by STORAGE_POSITION.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC721Storage | The ERC721Storage struct in storage. |
setApprovalForAll
Approves or revokes permission for an operator to manage all users's assets.
Parameters:
| Property | Type | Description |
|---|---|---|
_operator | address | The operator address to set approval for. |
_approved | bool | True to approve, false to revoke. |
Events
Errors
Best Practices
- Call
approveorsetApprovalForAllonly after verifying caller permissions if required by your facet's logic. - Ensure the
ERC721Storagestruct definition in your facet matches the one defined in this module to prevent storage collisions. - Handle potential errors like
ERC721NonexistentTokenorERC721InvalidOperatorwhen calling the module's functions.
Integration Notes
This module interacts with diamond storage at the slot identified by STORAGE_POSITION, which is defined as keccak256(\"erc721\"). It uses the ERC721Storage struct to manage approval data. All state modifications made through this module are written directly to this shared storage slot, making them immediately visible to any other facet within the same diamond that reads from or writes to this storage position.