Skip to content
Lattice

ERC721Lib

Git Source

Title: ERC721Lib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol)

Library implementing the ERC-721 Non-Fungible Token standard.

Mirrors OpenZeppelin v5.6.1 ERC721 logic. All state lives in an ERC-7201 slot. Hook model (decision D25, #234): _update calls no extension hook. An extension that gates or observes movement (Pausable, Enumerable, Votes) must replace the public transferFrom and both safeTransferFrom selectors instead, and two such extensions are mutually exclusive. A caller of _mint/_burn/_update outside those selectors (ERC721Burnable, ERC721Wrapper) bypasses them. The one exception is batch minting (ERC721ConsecutiveLib), which has no selector to replace: _ownerOf falls back to its ownership checkpoints, and _update applies its mint ban and burn bitmap, so every path sees batch-minted tokens. See docs/guides/selector-compatibility.md#token-extension-hook-model.

Functions

erc721Storage

function erc721Storage() internal pure returns (ERC721Storage storage $);

Returns

NameTypeDescription
$ERC721Storage

__ERC721_init

Initializes the ERC-721 module with name and symbol.

Must be called inside a pre/postInitializer block.

function __ERC721_init(string memory name_, string memory symbol_) internal;

Parameters

NameTypeDescription
name_string
symbol_string

registerInterfaces

Registers support for IERC721 and IERC721Metadata interfaces via ERC-165.

function registerInterfaces() internal;

name

Returns the token name.

function name() internal view returns (string memory);

Returns

NameTypeDescription
<none>string

symbol

Returns the token symbol.

function symbol() internal view returns (string memory);

Returns

NameTypeDescription
<none>string

balanceOf

Returns the number of tokens owned by owner.

function balanceOf(address owner) internal view returns (uint256);

Parameters

NameTypeDescription
owneraddress

Returns

NameTypeDescription
<none>uint256

ownerOf

Returns the owner of tokenId. Reverts if token does not exist.

function ownerOf(uint256 tokenId) internal view returns (address);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
<none>address

getApproved

Returns the address approved for tokenId. Reverts if token does not exist.

function getApproved(uint256 tokenId) internal view returns (address);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
<none>address

isApprovedForAll

Returns true if operator is approved to manage all of owner's assets.

function isApprovedForAll(address owner, address operator) internal view returns (bool);

Parameters

NameTypeDescription
owneraddress
operatoraddress

Returns

NameTypeDescription
<none>bool

_baseURI

Returns the base URI used for token URI computation.

Returns empty string by default. Facets may override tokenURI to supply a base.

function _baseURI() internal pure returns (string memory);

Returns

NameTypeDescription
<none>string

tokenURI

Returns the URI for tokenId. Concatenates _baseURI() + tokenId string if base is non-empty.

function tokenURI(uint256 tokenId) internal view returns (string memory);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
<none>string

approve

Approves to to transfer tokenId. Caller must be owner or approved operator.

function approve(address to, uint256 tokenId) internal;

Parameters

NameTypeDescription
toaddress
tokenIduint256

setApprovalForAll

Enables or disables approval for operator to manage all of the caller's assets.

function setApprovalForAll(address operator, bool approved) internal;

Parameters

NameTypeDescription
operatoraddress
approvedbool

transferFrom

Transfers tokenId from from to to without safety checks.

function transferFrom(address from, address to, uint256 tokenId) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256

safeTransferFrom

Safely transfers tokenId from from to to with additional data.

function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256
databytes

_ownerOf

Returns the owner of tokenId without reverting (zero address if nonexistent).

An id with no stored owner falls back to the batch-mint checkpoints of ERC721ConsecutiveLib, as OpenZeppelin's ERC721Consecutive _ownerOf override does. On a diamond without batches that costs one SLOAD, on a mint or a lookup of a nonexistent id. On a batch-minting diamond an untransferred batch token also reads the burn bitmap and binary-searches the checkpoints.

function _ownerOf(uint256 tokenId) internal view returns (address owner);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
owneraddress

_getApproved

Returns the approved address for tokenId without existence check.

function _getApproved(uint256 tokenId) internal view returns (address);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
<none>address

_isAuthorized

Returns true if spender is the owner or approved for tokenId.

function _isAuthorized(address owner, address spender, uint256 tokenId) internal view returns (bool);

Parameters

NameTypeDescription
owneraddress
spenderaddress
tokenIduint256

Returns

NameTypeDescription
<none>bool

_checkAuthorized

Reverts if spender is not authorized for tokenId.

function _checkAuthorized(address owner, address spender, uint256 tokenId) internal view;

Parameters

NameTypeDescription
owneraddress
spenderaddress
tokenIduint256

_update

Central state mutation. Transfers tokenId to to, authorized by auth.

If auth is non-zero, checks authorization. Returns previous owner. Runs no extension hook (D25); it only keeps the batch-mint state of ERC721ConsecutiveLib consistent: a mint reverts IERC721Consecutive.ERC721ForbiddenMint during a batch-minting diamond's first initialization (which also reads the initializable slot on each mint there), and a burn marks a batch id burned (one SLOAD per burn, plus the bitmap write for a batch id).

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

Parameters

NameTypeDescription
toaddress
tokenIduint256
authaddress

Returns

NameTypeDescription
fromaddress

_mint

Mints tokenId to to. Reverts if to is zero or token already exists.

An existing id reverts IERC721.ERC721InvalidSender with address(0), as OpenZeppelin does.

function _mint(address to, uint256 tokenId) internal;

Parameters

NameTypeDescription
toaddress
tokenIduint256

_safeMint

Safely mints tokenId to to, calling receiver hook if to is a contract.

The receiver sees msg.sender as operator, as OpenZeppelin does.

function _safeMint(address to, uint256 tokenId, bytes memory data) internal;

Parameters

NameTypeDescription
toaddress
tokenIduint256
databytes

_safeMint

Safely mints tokenId to to with empty data.

function _safeMint(address to, uint256 tokenId) internal;

Parameters

NameTypeDescription
toaddress
tokenIduint256

_burn

Burns tokenId. Reverts if token does not exist.

function _burn(uint256 tokenId) internal;

Parameters

NameTypeDescription
tokenIduint256

_approve

Approves to for tokenId. Optionally emits Approval event.

Guard matches OZ: enter owner-lookup block only when emitEvent OR auth != address(0). Uses _requireOwned (reverting) rather than _ownerOf to catch nonexistent tokens.

function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal;

Parameters

NameTypeDescription
toaddress
tokenIduint256
authaddress
emitEventbool

_setApprovalForAll

Sets or unsets the approval of operator by owner.

Reverts IERC721.ERC721InvalidApprover for a zero owner (added in OpenZeppelin v5.6), then IERC721.ERC721InvalidOperator for a zero operator.

function _setApprovalForAll(address owner, address operator, bool approved) internal;

Parameters

NameTypeDescription
owneraddress
operatoraddress
approvedbool

_increaseBalance

Increases the balance of account by value without minting a tracked token.

Used by ERC721ConsecutiveLib._mintConsecutive, whose batch owners live outside _owners. Matches OZ's _increaseBalance.

function _increaseBalance(address account, uint128 value) internal;

Parameters

NameTypeDescription
accountaddress
valueuint128

_transfer

Transfers tokenId from from to to bypassing msg.sender authorization.

For permissioned or signature-based transfer mechanisms. Validates that the token exists, so a zero from cannot mint, and that from is its previous owner.

function _transfer(address from, address to, uint256 tokenId) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256

_safeTransfer

Safely transfers tokenId from from to to with data, bypassing authorization.

Calls receiver hook if to is a contract; the receiver sees msg.sender as operator.

function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
tokenIduint256
databytes

_requireOwned

Reverts if tokenId does not exist. Returns the owner.

function _requireOwned(uint256 tokenId) internal view returns (address);

Parameters

NameTypeDescription
tokenIduint256

Returns

NameTypeDescription
<none>address

_checkOnERC721Received

Calls IERC721Receiver.onERC721Received if to is a contract.

Distinguishes between a non-implementor (empty revert) and a deliberate revert from the receiver (non-empty reason). Non-empty reasons are re-bubbled verbatim so callers see the actual error from the receiver contract.

function _checkOnERC721Received(address operator, address from, address to, uint256 tokenId, bytes memory data)
        internal;

Parameters

NameTypeDescription
operatoraddress
fromaddress
toaddress
tokenIduint256
databytes

_toString

Converts a uint256 to its decimal string representation.

function _toString(uint256 value) internal pure returns (string memory);

Parameters

NameTypeDescription
valueuint256

Returns

NameTypeDescription
<none>string