TokenEnumerable
Inherits: ContextUpgradeable
Author: EVMAuth
Manages sequential token ID generation and existence tracking.
Abstract contract providing auto-incrementing sequential token IDs starting at 1. Uses EIP-7201 storage pattern for upgrade safety.
State Variables
TokenEnumerableStorageLocation
EIP-7201 storage slot for TokenEnumerable state.
Computed as: keccak256(abi.encode(uint256(keccak256("tokenenumerable.storage.TokenEnumerable")) - 1)) & ~bytes32(uint256(0xff)). Prevents storage collisions in upgradeable contracts.
bytes32 private constant TokenEnumerableStorageLocation =
0x591f2d2df77efc80b9969dfd51dd4fc103fe490745902503f7c21df07a35d600;
Functions
_getTokenEnumerableStorage
Retrieves the storage struct for TokenEnumerable.
Internal function using inline assembly for direct storage access.
function _getTokenEnumerableStorage() private pure returns (TokenEnumerableStorage storage $);
Returns
Name | Type | Description |
---|---|---|
$ | TokenEnumerableStorage | Storage pointer to TokenEnumerableStorage struct |
tokenExists
Validates that a token ID exists before proceeding.
Modifier reverting with InvalidTokenID if token doesn't exist.
modifier tokenExists(uint256 id);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | Token ID to validate |
allTokensExist
Validates that all token IDs in array exist.
Modifier reverting with InvalidTokenID if any token doesn't exist.
modifier allTokensExist(uint256[] memory ids);
Parameters
Name | Type | Description |
---|---|---|
ids | uint256[] | Array of token IDs to validate |
__TokenEnumerable_init
Internal initializer for TokenEnumerable setup.
Initializes Context and sets up token enumeration.
function __TokenEnumerable_init() internal onlyInitializing;
__TokenEnumerable_init_unchained
Unchained initializer for contract-specific storage.
Sets initial nextTokenID to 1 (tokens start from ID 1, not 0)
function __TokenEnumerable_init_unchained() internal onlyInitializing;
nextTokenID
Gets the next available token ID.
Public view function for upcoming token ID.
function nextTokenID() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | Next sequential token ID to be assigned |
exists
Checks if a token ID has been created.
Token exists if ID is between 1 and nextTokenID (exclusive)
function exists(uint256 id) public view virtual returns (bool);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | Token ID to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | True if token has been created, false otherwise |
_claimNextTokenID
Claims and returns the next sequential token ID.
Internal function that auto-increments nextTokenID after claiming.
function _claimNextTokenID() internal virtual returns (uint256 id);
Returns
Name | Type | Description |
---|---|---|
id | uint256 | Newly claimed token ID |
Errors
InvalidTokenID
Error thrown for operations on non-existent token IDs.
error InvalidTokenID(uint256 id);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | The invalid token ID |
Structs
TokenEnumerableStorage
Note: storage-location: erc7201:tokenenumerable.storage.TokenEnumerable
struct TokenEnumerableStorage {
uint256 nextTokenID;
}