Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERC721EnumerableUpgradeable

Inherits: Initializable, ERC721Upgradeable, IERC721Enumerable

This implements an optional extension of {ERC721} defined in the ERC that adds enumerability of all the token ids in the contract as well as all token ids owned by each account. CAUTION: {ERC721} extensions that implement custom balanceOf logic, such as {ERC721Consecutive}, interfere with enumerability and should not be used together with {ERC721Enumerable}.

State Variables

ERC721EnumerableStorageLocation

bytes32 private constant ERC721EnumerableStorageLocation =
    0x645e039705490088daad89bae25049a34f4a9072d398537b1ab2425f24cbed00;

Functions

_getERC721EnumerableStorage

function _getERC721EnumerableStorage() private pure returns (ERC721EnumerableStorage storage $);

__ERC721Enumerable_init

function __ERC721Enumerable_init() internal onlyInitializing;

__ERC721Enumerable_init_unchained

function __ERC721Enumerable_init_unchained() internal onlyInitializing;

supportsInterface

Query if a contract implements an interface

Interface identification is specified in ERC-165. This function uses less than 30,000 gas.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(IERC165, ERC721Upgradeable)
    returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>booltrue if the contract implements interfaceID and interfaceID is not 0xffffffff, false otherwise

tokenOfOwnerByIndex

Enumerate NFTs assigned to an owner

Throws if _index >= balanceOf(_owner) or if _owner is the zero address, representing invalid NFTs.

function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256);

Parameters

NameTypeDescription
owneraddress
indexuint256

Returns

NameTypeDescription
<none>uint256The token identifier for the _indexth NFT assigned to _owner, (sort order not specified)

totalSupply

Count NFTs tracked by this contract

function totalSupply() public view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256A count of valid NFTs tracked by this contract, where each one of them has an assigned and queryable owner not equal to the zero address

tokenByIndex

Enumerate valid NFTs

Throws if _index >= totalSupply().

function tokenByIndex(uint256 index) public view virtual returns (uint256);

Parameters

NameTypeDescription
indexuint256

Returns

NameTypeDescription
<none>uint256The token identifier for the _indexth NFT, (sort order not specified)

_update

Transfers tokenId from its current owner to to, or alternatively mints (or burns) if the current owner (or to) is the zero address. Returns the owner of the tokenId before the update. The auth argument is optional. If the value passed is non 0, then this function will check that auth is either the owner of the token, or approved to operate on the token (by the owner). Emits a {Transfer} event. NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.

function _update(address to, uint256 tokenId, address auth) internal virtual override returns (address);

_addTokenToOwnerEnumeration

Private function to add a token to this extension's ownership-tracking data structures.

function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private;

Parameters

NameTypeDescription
toaddressaddress representing the new owner of the given token ID
tokenIduint256uint256 ID of the token to be added to the tokens list of the given address

_addTokenToAllTokensEnumeration

Private function to add a token to this extension's token tracking data structures.

function _addTokenToAllTokensEnumeration(uint256 tokenId) private;

Parameters

NameTypeDescription
tokenIduint256uint256 ID of the token to be added to the tokens list

_removeTokenFromOwnerEnumeration

Private function to remove a token from this extension's ownership-tracking data structures. Note that while the token is not assigned a new owner, the _ownedTokensIndex mapping is not updated: this allows for gas optimizations e.g. when performing a transfer operation (avoiding double writes). This has O(1) time complexity, but alters the order of the _ownedTokens array.

function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private;

Parameters

NameTypeDescription
fromaddressaddress representing the previous owner of the given token ID
tokenIduint256uint256 ID of the token to be removed from the tokens list of the given address

_removeTokenFromAllTokensEnumeration

Private function to remove a token from this extension's token tracking data structures. This has O(1) time complexity, but alters the order of the _allTokens array.

function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private;

Parameters

NameTypeDescription
tokenIduint256uint256 ID of the token to be removed from the tokens list

_increaseBalance

See ERC721-_increaseBalance. We need that to account tokens that were minted in batch

function _increaseBalance(address account, uint128 amount) internal virtual override;

Errors

ERC721OutOfBoundsIndex

An owner's token query was out of bounds for index. NOTE: The owner being address(0) indicates a global out of bounds index.

error ERC721OutOfBoundsIndex(address owner, uint256 index);

ERC721EnumerableForbiddenBatchMint

Batch mint is not allowed.

error ERC721EnumerableForbiddenBatchMint();

Structs

ERC721EnumerableStorage

Note: storage-location: erc7201:openzeppelin.storage.ERC721Enumerable

struct ERC721EnumerableStorage {
    mapping(address owner => mapping(uint256 index => uint256)) _ownedTokens;
    mapping(uint256 tokenId => uint256) _ownedTokensIndex;
    uint256[] _allTokens;
    mapping(uint256 tokenId => uint256) _allTokensIndex;
}