Skip to main content

ERC-721 Approve Facet

Manage ERC-721 approvals within a diamond

Key Features
  • Exposes external functions for ERC-721 approval management.
  • Interacts with shared diamond storage via ERC721Storage.
  • Supports approve and setApprovalForAll operations.
  • Provides exportSelectors for 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

Definition
struct ERC721Storage {
mapping(uint256 tokenId => address owner) ownerOf;
mapping(address owner => uint256 balance) balanceOf;
mapping(address owner => mapping(address operator => bool approved)) isApprovedForAll;
mapping(uint256 tokenId => address approved) approved;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc721"))

Functions

approve

Approves another address to transfer the given token ID.

function approve(address _to, uint256 _tokenId) external;

Parameters:

PropertyTypeDescription
_toaddressThe address to be approved.
_tokenIduint256The token ID to approve.

setApprovalForAll

Approves or revokes permission for an operator to manage all caller's assets.

function setApprovalForAll(address _operator, bool _approved) external;

Parameters:

PropertyTypeDescription
_operatoraddressThe operator address to set approval for.
_approvedboolTrue to approve, false to revoke.

exportSelectors

Exports the function selectors of the ERC721ApproveFacet This function is use as a selector discovery mechanism for diamonds

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC721ApproveFacet

Events

Errors

Best Practices

Best Practice
  • 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_POSITION is compatible with previous versions to prevent data loss.

Security Considerations

Security

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.