ERC-721 Approve Facet
Manage ERC-721 approvals within a diamond
- Exposes external functions for ERC-721 approval management.
- Interacts with shared diamond storage via
ERC721Storage. - Supports
approveandsetApprovalForAlloperations. - Provides
exportSelectorsfor discovery within a diamond.
Overview
This facet provides external functions for managing ERC-721 token approvals within a diamond. It interacts with shared diamond storage to track token ownership and approvals. Developers integrate this facet to enable external calls for approving token transfers and operator permissions, ensuring upgradeability and composability.
Storage
ERC721Storage
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. |
setApprovalForAll
Approves or revokes permission for an operator to manage all caller's assets.
Parameters:
| Property | Type | Description |
|---|---|---|
_operator | address | The operator address to set approval for. |
_approved | bool | True to approve, false to revoke. |
exportSelectors
Exports the function selectors of the ERC721ApproveFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC721ApproveFacet |
Events
Errors
Best Practices
- Initialize the facet and its associated storage correctly during diamond deployment.
- Ensure that access control for state-changing functions aligns with your diamond's security model.
- When upgrading, verify that the storage slot
STORAGE_POSITIONis compatible with previous versions to prevent data loss.
Security Considerations
The approve function reverts with ERC721NonexistentToken if the token ID does not exist, and ERC721InvalidApprover if the caller is not the owner or approved delegate. The setApprovalForAll function reverts with ERC721InvalidOperator if the operator is the caller. Follow standard Solidity security practices for input validation and access control.