ERC721
Smart contract ERC721 utilities and implementations
This set of interfaces, contracts, and utilities is all related to the ERC-721 Non-Fungible Token Standard.
For a walk through on how to create an ERC-721 token read our ERC-721 guide.
The ERC specifies four interfaces:
IERC721: Core functionality required in all compliant implementation.IERC721Metadata: Optional extension that adds name, symbol, and token URI, almost always included.IERC721Enumerable: Optional extension that allows enumerating the tokens on chain, often not included since it requires large gas overhead.IERC721Receiver: An interface that must be implemented by contracts if they want to accept tokens throughsafeTransferFrom.
OpenZeppelin Contracts provides implementations of all four interfaces:
ERC721: The core and metadata extensions, with a base URI mechanism.ERC721Enumerable: The enumerable extension.ERC721Holder: A bare bones implementation of the receiver interface.
Additionally there are a few of other extensions:
ERC721Consecutive: An implementation of ERC-2309 for minting batches of tokens during construction, in accordance with ERC-721.ERC721URIStorage: A more flexible but more expensive way of storing metadata.ERC721Votes: Support for voting and vote delegation.ERC721Royalty: A way to signal royalty information following ERC-2981.ERC721Pausable: A primitive to pause contract operation.ERC721Burnable: A way for token holders to burn their own tokens.ERC721Wrapper: Wrapper to create an ERC-721 backed by another ERC-721, with deposit and withdraw methods. Useful in conjunction withERC721Votes.
This core set of contracts is designed to be unopinionated, allowing developers to access the internal functions in ERC-721 (such as _mint) and expose them as external functions in the way they prefer.
Core
Extensions
Utilities
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";Implementation of ERC-721 Non-Fungible Token Standard, including
the Metadata extension, but not including the Enumerable extension, which is available separately as
ERC721Enumerable.
Functions
- constructor(name_, symbol_)
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _update(to, tokenId, auth)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Errors
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
constructor(string name_, string symbol_)
internal
#Initializes the contract by setting a name and a symbol to the token collection.
supportsInterface(bytes4 interfaceId) → bool
public
#Returns true if this contract implements the interface defined by
interfaceId. See the corresponding
ERC section
to learn more about how these ids are created.
This function call must use less than 30 000 gas.
balanceOf(address owner) → uint256
public
#Returns the number of tokens in owner's account.
ownerOf(uint256 tokenId) → address
public
#Returns the owner of the tokenId token.
Requirements:
tokenIdmust exist.
name() → string
public
#Returns the token collection name.
symbol() → string
public
#Returns the token collection symbol.
tokenURI(uint256 tokenId) → string
public
#Returns the Uniform Resource Identifier (URI) for tokenId token.
_baseURI() → string
internal
#Base URI for computing IERC6909ContentURI.tokenURI. If set, the resulting URI for each
token will be the concatenation of the baseURI and the tokenId. Empty
by default, can be overridden in child contracts.
approve(address to, uint256 tokenId)
public
#Gives permission to to to transfer tokenId token to another account.
The approval is cleared when the token is transferred.
Only a single account can be approved at a time, so approving the zero address clears previous approvals.
Requirements:
- The caller must own the token or be an approved operator.
tokenIdmust exist.
Emits an IERC6909.Approval event.
getApproved(uint256 tokenId) → address
public
#Returns the account approved for tokenId token.
Requirements:
tokenIdmust exist.
setApprovalForAll(address operator, bool approved)
public
#Approve or remove operator as an operator for the caller.
Operators can call IERC6909.transferFrom or ERC1155.safeTransferFrom for any token owned by the caller.
Requirements:
- The
operatorcannot be the address zero.
Emits an IERC1155.ApprovalForAll event.
isApprovedForAll(address owner, address operator) → bool
public
#Returns if the operator is allowed to manage all of the assets of owner.
transferFrom(address from, address to, uint256 tokenId)
public
#Transfers tokenId token from from to to.
Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
or else they may be permanently lost. Usage of ERC1155.safeTransferFrom prevents loss, though the caller must
understand this adds an external call which potentially creates a reentrancy vulnerability.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must be owned byfrom.- If the caller is not
from, it must be approved to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll.
Emits a IERC6909.Transfer event.
safeTransferFrom(address from, address to, uint256 tokenId)
public
#Safely transfers tokenId token from from to to, checking first that contract recipients
are aware of the ERC-721 protocol to prevent tokens from being forever locked.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must have been allowed to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll. - If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
safeTransferFrom(address from, address to, uint256 tokenId, bytes data)
public
#Safely transfers tokenId token from from to to.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must be approved to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll. - If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
_ownerOf(uint256 tokenId) → address
internal
#Returns the owner of the tokenId. Does NOT revert if token doesn't exist
Any overrides to this function that add ownership of tokens not tracked by the
core ERC-721 logic MUST be matched with the use of ERC721._increaseBalance to keep balances
consistent with ownership. The invariant to preserve is that for any address a the value returned by
balanceOf(a) must be equal to the number of tokens such that _ownerOf(tokenId) is a.
_getApproved(uint256 tokenId) → address
internal
#Returns the approved address for tokenId. Returns 0 if tokenId is not minted.
_isAuthorized(address owner, address spender, uint256 tokenId) → bool
internal
#Returns whether spender is allowed to manage owner's tokens, or tokenId in
particular (ignoring whether it is owned by owner).
This function assumes that owner is the actual owner of tokenId and does not verify this
assumption.
_checkAuthorized(address owner, address spender, uint256 tokenId)
internal
#Checks if spender can operate on tokenId, assuming the provided owner is the actual owner.
Reverts if:
spenderdoes not have approval fromownerfortokenId.spenderdoes not have approval to manage all ofowner's assets.
This function assumes that owner is the actual owner of tokenId and does not verify this
assumption.
_increaseBalance(address account, uint128 value)
internal
#Unsafe write access to the balances, used by extensions that "mint" tokens using an ERC721.ownerOf override.
the value is limited to type(uint128).max. This protect against _balance overflow. It is unrealistic that a uint256 would ever overflow from increments when these increments are bounded to uint128 values.
Increasing an account's balance using this function tends to be paired with an override of the
ERC721._ownerOf function to resolve the ownership of the corresponding tokens so that balances and ownership
remain consistent with one another.
_update(address to, uint256 tokenId, address auth) → address
internal
#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 IERC6909.Transfer event.
If overriding this function in a way that tracks balances, see also ERC721._increaseBalance.
_mint(address to, uint256 tokenId)
internal
#Mints tokenId and transfers it to to.
Usage of this method is discouraged, use ERC721._safeMint whenever possible
Requirements:
tokenIdmust not exist.tocannot be the zero address.
Emits a IERC6909.Transfer event.
_safeMint(address to, uint256 tokenId)
internal
#Mints tokenId, transfers it to to and checks for to acceptance.
Requirements:
tokenIdmust not exist.- If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
_safeMint(address to, uint256 tokenId, bytes data)
internal
#Same as _safeMint, with an additional data parameter which is
forwarded in IERC721Receiver.onERC721Received to contract recipients.
_burn(uint256 tokenId)
internal
#Destroys tokenId.
The approval is cleared when the token is burned.
This is an internal function that does not check if the sender is authorized to operate on the token.
Requirements:
tokenIdmust exist.
Emits a IERC6909.Transfer event.
_transfer(address from, address to, uint256 tokenId)
internal
#Transfers tokenId from from to to.
As opposed to IERC6909.transferFrom, this imposes no restrictions on msg.sender.
Requirements:
tocannot be the zero address.tokenIdtoken must be owned byfrom.
Emits a IERC6909.Transfer event.
_safeTransfer(address from, address to, uint256 tokenId)
internal
#Safely transfers tokenId token from from to to, checking that contract recipients
are aware of the ERC-721 standard to prevent tokens from being forever locked.
data is additional data, it has no specified format and it is sent in call to to.
This internal function is like ERC1155.safeTransferFrom in the sense that it invokes
IERC721Receiver.onERC721Received on the receiver, and can be used to e.g.
implement alternative mechanisms to perform token transfer, such as signature-based.
Requirements:
tokenIdtoken must exist and be owned byfrom.tocannot be the zero address.fromcannot be the zero address.- If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
_safeTransfer(address from, address to, uint256 tokenId, bytes data)
internal
#Same as _safeTransfer, with an additional data parameter which is
forwarded in IERC721Receiver.onERC721Received to contract recipients.
_approve(address to, uint256 tokenId, address auth)
internal
#Approve to to operate on tokenId
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 all tokens held by this owner.
Emits an IERC6909.Approval event.
Overrides to this logic should be done to the variant with an additional bool emitEvent argument.
_approve(address to, uint256 tokenId, address auth, bool emitEvent)
internal
#Variant of _approve with an optional flag to enable or disable the IERC6909.Approval event. The event is not
emitted in the context of transfers.
_setApprovalForAll(address owner, address operator, bool approved)
internal
#Approve operator to operate on all of owner tokens
Requirements:
- operator can't be the address zero.
Emits an IERC1155.ApprovalForAll event.
_requireOwned(uint256 tokenId) → address
internal
#Reverts if the tokenId doesn't have a current owner (it hasn't been minted, or it has been burned).
Returns the owner.
Overrides to ownership logic should be done to ERC721._ownerOf.
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";Required interface of an ERC-721 compliant contract.
Functions
Events
balanceOf(address owner) → uint256 balance
external
#Returns the number of tokens in owner's account.
ownerOf(uint256 tokenId) → address owner
external
#Returns the owner of the tokenId token.
Requirements:
tokenIdmust exist.
safeTransferFrom(address from, address to, uint256 tokenId, bytes data)
external
#Safely transfers tokenId token from from to to.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must be approved to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll. - If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
safeTransferFrom(address from, address to, uint256 tokenId)
external
#Safely transfers tokenId token from from to to, checking first that contract recipients
are aware of the ERC-721 protocol to prevent tokens from being forever locked.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If the caller is not
from, it must have been allowed to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll. - If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a IERC6909.Transfer event.
transferFrom(address from, address to, uint256 tokenId)
external
#Transfers tokenId token from from to to.
Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
or else they may be permanently lost. Usage of ERC1155.safeTransferFrom prevents loss, though the caller must
understand this adds an external call which potentially creates a reentrancy vulnerability.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must be owned byfrom.- If the caller is not
from, it must be approved to move this token by eitherIERC6909.approveorERC1155.setApprovalForAll.
Emits a IERC6909.Transfer event.
approve(address to, uint256 tokenId)
external
#Gives permission to to to transfer tokenId token to another account.
The approval is cleared when the token is transferred.
Only a single account can be approved at a time, so approving the zero address clears previous approvals.
Requirements:
- The caller must own the token or be an approved operator.
tokenIdmust exist.
Emits an IERC6909.Approval event.
setApprovalForAll(address operator, bool approved)
external
#Approve or remove operator as an operator for the caller.
Operators can call IERC6909.transferFrom or ERC1155.safeTransferFrom for any token owned by the caller.
Requirements:
- The
operatorcannot be the address zero.
Emits an IERC1155.ApprovalForAll event.
getApproved(uint256 tokenId) → address operator
external
#Returns the account approved for tokenId token.
Requirements:
tokenIdmust exist.
isApprovedForAll(address owner, address operator) → bool
external
#Returns if the operator is allowed to manage all of the assets of owner.
Transfer(address indexed from, address indexed to, uint256 indexed tokenId)
event
#Emitted when tokenId token is transferred from from to to.
Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)
event
#Emitted when owner enables approved to manage the tokenId token.
ApprovalForAll(address indexed owner, address indexed operator, bool approved)
event
#Emitted when owner enables or disables (approved) operator to manage all of its assets.
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";Interface for any contract that wants to support safeTransfers from ERC-721 asset contracts.
onERC721Received(address operator, address from, uint256 tokenId, bytes data) → bytes4
external
#Whenever an IERC721 tokenId token is transferred to this contract via IERC721.safeTransferFrom
by operator from from, this function is called.
It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
The selector can be obtained in Solidity with IERC721Receiver.onERC721Received.selector.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";ERC-721 Token that can be burned (destroyed).
Functions
ERC721
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _update(to, tokenId, auth)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Errors
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
burn(uint256 tokenId)
public
#Burns tokenId. See ERC721._burn.
Requirements:
- The caller must own
tokenIdor be an approved operator.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Consecutive.sol";Implementation of the ERC-2309 "Consecutive Transfer Extension" as defined in ERC-2309.
This extension allows the minting of large batches of tokens, during contract construction only. For upgradeable contracts this implies that batch minting is only available during proxy deployment, and not in subsequent upgrades. These batches are limited to 5000 tokens at a time by default to accommodate off-chain indexers.
Using this extension removes the ability to mint single tokens during contract construction. This ability is regained after construction. During construction, only batch minting is allowed.
This extension does not call the ERC1155._update function for tokens minted in batch. Any logic added to this
function through overrides will not be triggered when token are minted in batch. You may want to also override
ERC721._increaseBalance or ERC721Consecutive._mintConsecutive to account for these mints.
When overriding ERC721Consecutive._mintConsecutive, be careful about call ordering. ERC721.ownerOf may return invalid
values during the ERC721Consecutive._mintConsecutive execution if the super call is not called first. To be safe, execute the
super call before your custom logic.
Functions
- _maxBatchSize()
- _ownerOf(tokenId)
- _mintConsecutive(to, batchSize)
- _update(to, tokenId, auth)
- _firstConsecutiveId()
ERC721
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
IERC2309
Events
Errors
- ERC721ForbiddenBatchMint()
- ERC721ExceededMaxBatchMint(batchSize, maxBatch)
- ERC721ForbiddenMint()
- ERC721ForbiddenBatchBurn()
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
IERC2309
_maxBatchSize() → uint96
internal
#Maximum size of a batch of consecutive tokens. This is designed to limit stress on off-chain indexing services that have to record one entry per token, and have protections against "unreasonably large" batches of tokens.
Overriding the default value of 5000 will not cause on-chain issues, but may result in the asset not being correctly supported by off-chain indexing services (including marketplaces).
_ownerOf(uint256 tokenId) → address
internal
#See ERC721._ownerOf. Override that checks the sequential ownership structure for tokens that have
been minted as part of a batch, and not yet transferred.
_mintConsecutive(address to, uint96 batchSize) → uint96
internal
#Mint a batch of tokens of length batchSize for to. Returns the token id of the first token minted in the
batch; if batchSize is 0, returns the number of consecutive ids minted so far.
Requirements:
batchSizemust not be greater thanERC721Consecutive._maxBatchSize.- The function is called in the constructor of the contract (directly or indirectly).
CAUTION: Does not emit a Transfer event. This is ERC-721 compliant as long as it is done inside of the
constructor, which is enforced by this function.
CAUTION: Does not invoke onERC721Received on the receiver.
Emits a IERC2309.ConsecutiveTransfer event.
_update(address to, uint256 tokenId, address auth) → address
internal
#See ERC721._update. Override version that restricts normal minting to after construction.
Using ERC721Consecutive prevents minting during construction in favor of ERC721Consecutive._mintConsecutive.
After construction, ERC721Consecutive._mintConsecutive is no longer available and minting through ERC1155._update becomes available.
_firstConsecutiveId() → uint96
internal
#Used to offset the first token id in _nextConsecutiveId
ERC721ForbiddenBatchMint()
error
#Batch mint is restricted to the constructor.
Any batch mint not emitting the IERC721.Transfer event outside of the constructor
is non ERC-721 compliant.
ERC721ExceededMaxBatchMint(uint256 batchSize, uint256 maxBatch)
error
#Exceeds the max amount of mints per batch.
ERC721ForbiddenMint()
error
#Individual minting is not allowed.
ERC721ForbiddenBatchBurn()
error
#Batch burn is not supported.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";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.
Functions
- supportsInterface(interfaceId)
- tokenOfOwnerByIndex(owner, index)
- totalSupply()
- tokenByIndex(index)
- _update(to, tokenId, auth)
- _increaseBalance(account, amount)
IERC721Enumerable
ERC721
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Errors
IERC721Enumerable
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
supportsInterface(bytes4 interfaceId) → bool
public
#Returns true if this contract implements the interface defined by
interfaceId. See the corresponding
ERC section
to learn more about how these ids are created.
This function call must use less than 30 000 gas.
tokenOfOwnerByIndex(address owner, uint256 index) → uint256
public
#Returns a token ID owned by owner at a given index of its token list.
Use along with IERC777.balanceOf to enumerate all of owner's tokens.
totalSupply() → uint256
public
#Returns the total amount of tokens stored by the contract.
tokenByIndex(uint256 index) → uint256
public
#Returns a token ID at a given index of all the tokens stored by the contract.
Use along with IERC777.totalSupply to enumerate all tokens.
_update(address to, uint256 tokenId, address auth) → address
internal
#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 IERC6909.Transfer event.
If overriding this function in a way that tracks balances, see also ERC721._increaseBalance.
_increaseBalance(address account, uint128 amount)
internal
#ERC721OutOfBoundsIndex(address owner, uint256 index)
error
#An owner's token query was out of bounds for index.
The owner being address(0) indicates a global out of bounds index.
ERC721EnumerableForbiddenBatchMint()
error
#Batch mint is not allowed.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol";ERC-721 token with pausable token transfers, minting and burning.
Useful for scenarios such as preventing trades until the end of an evaluation period, or having an emergency switch for freezing all token transfers in the event of a large bug.
This contract does not include public pause and unpause functions. In
addition to inheriting this contract, you must define both functions, invoking the
Pausable._pause and Pausable._unpause internal functions, with appropriate
access control, e.g. using AccessControl or Ownable. Not doing so will
make the contract pause mechanism of the contract unreachable, and thus unusable.
Functions
Pausable
ERC721
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Errors
Pausable
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
_update(address to, uint256 tokenId, address auth) → address
internal
#import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol";Extension of ERC-721 with the ERC-2981 NFT Royalty Standard, a standardized way to retrieve royalty payment information.
Royalty information can be specified globally for all token ids via ERC2981._setDefaultRoyalty, and/or individually
for specific token ids via ERC2981._setTokenRoyalty. The latter takes precedence over the first.
ERC-2981 only specifies a way to signal royalty information and does not enforce its payment. See Rationale in the ERC. Marketplaces are expected to voluntarily pay royalties together with sales, but note that this standard is not yet widely supported.
Functions
ERC721
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _update(to, tokenId, auth)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC2981
- royaltyInfo(tokenId, salePrice)
- _feeDenominator()
- _setDefaultRoyalty(receiver, feeNumerator)
- _deleteDefaultRoyalty()
- _setTokenRoyalty(tokenId, receiver, feeNumerator)
- _resetTokenRoyalty(tokenId)
ERC165
IERC2981
IERC165
Events
Errors
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC2981
- ERC2981InvalidDefaultRoyalty(numerator, denominator)
- ERC2981InvalidDefaultRoyaltyReceiver(receiver)
- ERC2981InvalidTokenRoyalty(tokenId, numerator, denominator)
- ERC2981InvalidTokenRoyaltyReceiver(tokenId, receiver)
ERC165
IERC2981
IERC165
supportsInterface(bytes4 interfaceId) → bool
public
#import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";ERC-721 token with storage based token URI management.
Functions
ERC721
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _update(to, tokenId, auth)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC4906
IERC721
ERC165
IERC165
Events
Errors
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC4906
IERC721
ERC165
IERC165
supportsInterface(bytes4 interfaceId) → bool
public
#Returns true if this contract implements the interface defined by
interfaceId. See the corresponding
ERC section
to learn more about how these ids are created.
This function call must use less than 30 000 gas.
tokenURI(uint256 tokenId) → string
public
#_setTokenURI(uint256 tokenId, string _tokenURI)
internal
#Sets _tokenURI as the tokenURI of tokenId.
Emits IERC4906.MetadataUpdate.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Votes.sol";Extension of ERC-721 to support voting and delegation as implemented by Votes, where each individual NFT counts
as 1 vote unit.
Tokens do not count as votes until they are delegated, because votes must be tracked which incurs an additional cost on every transfer. Token holders can either delegate to a trusted representative who will decide how to make use of the votes in governance decisions, or they can delegate to themselves to be their own representative.
Functions
Votes
- clock()
- CLOCK_MODE()
- _validateTimepoint(timepoint)
- getVotes(account)
- getPastVotes(account, timepoint)
- getPastTotalSupply(timepoint)
- _getTotalSupply()
- delegates(account)
- delegate(delegatee)
- delegateBySig(delegatee, nonce, expiry, v, r, s)
- _delegate(account, delegatee)
- _transferVotingUnits(from, to, amount)
- _moveDelegateVotes(from, to, amount)
- _numCheckpoints(account)
- _checkpoints(account, pos)
IERC5805
IVotes
IERC6372
Nonces
EIP712
IERC5267
ERC721
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Votes
IERC5805
IVotes
- DelegateChanged(delegator, fromDelegate, toDelegate)
- DelegateVotesChanged(delegate, previousVotes, newVotes)
IERC6372
Nonces
EIP712
IERC5267
ERC721
IERC721Errors
IERC721Metadata
IERC721
- Transfer(from, to, tokenId)
- Approval(owner, approved, tokenId)
- ApprovalForAll(owner, operator, approved)
ERC165
IERC165
Errors
Votes
IERC5805
IVotes
IERC6372
Nonces
EIP712
IERC5267
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
_update(address to, uint256 tokenId, address auth) → address
internal
#See ERC721._update. Adjusts votes when tokens are transferred.
Emits a IVotes.DelegateVotesChanged event.
_getVotingUnits(address account) → uint256
internal
#Returns the balance of account.
Overriding this function will likely result in incorrect vote tracking.
_increaseBalance(address account, uint128 amount)
internal
#See ERC721._increaseBalance. We need that to account tokens that were minted in batch.
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Wrapper.sol";Extension of the ERC-721 token contract to support token wrapping.
Users can deposit and withdraw an "underlying token" and receive a "wrapped token" with a matching tokenId. This is
useful in conjunction with other modules. For example, combining this wrapping mechanism with ERC721Votes will allow
the wrapping of an existing "basic" ERC-721 into a governance token.
Functions
- constructor(underlyingToken)
- depositFor(account, tokenIds)
- withdrawTo(account, tokenIds)
- onERC721Received(, from, tokenId, )
- _recover(account, tokenId)
- underlying()
IERC721Receiver
ERC721
- supportsInterface(interfaceId)
- balanceOf(owner)
- ownerOf(tokenId)
- name()
- symbol()
- tokenURI(tokenId)
- _baseURI()
- approve(to, tokenId)
- getApproved(tokenId)
- setApprovalForAll(operator, approved)
- isApprovedForAll(owner, operator)
- transferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId)
- safeTransferFrom(from, to, tokenId, data)
- _ownerOf(tokenId)
- _getApproved(tokenId)
- _isAuthorized(owner, spender, tokenId)
- _checkAuthorized(owner, spender, tokenId)
- _increaseBalance(account, value)
- _update(to, tokenId, auth)
- _mint(to, tokenId)
- _safeMint(to, tokenId)
- _safeMint(to, tokenId, data)
- _burn(tokenId)
- _transfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId)
- _safeTransfer(from, to, tokenId, data)
- _approve(to, tokenId, auth)
- _approve(to, tokenId, auth, emitEvent)
- _setApprovalForAll(owner, operator, approved)
- _requireOwned(tokenId)
IERC721Errors
IERC721Metadata
IERC721
ERC165
IERC165
Events
Errors
IERC721Receiver
ERC721
IERC721Errors
- ERC721InvalidOwner(owner)
- ERC721NonexistentToken(tokenId)
- ERC721IncorrectOwner(sender, tokenId, owner)
- ERC721InvalidSender(sender)
- ERC721InvalidReceiver(receiver)
- ERC721InsufficientApproval(operator, tokenId)
- ERC721InvalidApprover(approver)
- ERC721InvalidOperator(operator)
IERC721Metadata
IERC721
ERC165
IERC165
constructor(contract IERC721 underlyingToken)
internal
#depositFor(address account, uint256[] tokenIds) → bool
public
#Allow a user to deposit underlying tokens and mint the corresponding tokenIds.
withdrawTo(address account, uint256[] tokenIds) → bool
public
#Allow a user to burn wrapped tokens and withdraw the corresponding tokenIds of the underlying tokens.
onERC721Received(address, address from, uint256 tokenId, bytes) → bytes4
public
#Overrides IERC721Receiver.onERC721Received to allow minting on direct ERC-721 transfers to
this contract.
In case there's data attached, it validates that the operator is this contract, so only trusted data
is accepted from ERC20Wrapper.depositFor.
Doesn't work with unsafe transfers (eg. IERC721.transferFrom). Use ERC721Wrapper._recover
for recovering in that scenario.
_recover(address account, uint256 tokenId) → uint256
internal
#Mint a wrapped token to cover any underlyingToken that would have been transferred by mistake. Internal function that can be exposed with access control if desired.
underlying() → contract IERC721
public
#Returns the underlying token.
ERC721UnsupportedToken(address token)
error
#The received ERC-721 token couldn't be wrapped.
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";See https://eips.ethereum.org/EIPS/eip-721
Functions
Events
totalSupply() → uint256
external
#Returns the total amount of tokens stored by the contract.
tokenOfOwnerByIndex(address owner, uint256 index) → uint256
external
#Returns a token ID owned by owner at a given index of its token list.
Use along with IERC777.balanceOf to enumerate all of owner's tokens.
tokenByIndex(uint256 index) → uint256
external
#Returns a token ID at a given index of all the tokens stored by the contract.
Use along with IERC777.totalSupply to enumerate all tokens.
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";See https://eips.ethereum.org/EIPS/eip-721
Functions
Events
name() → string
external
#Returns the token collection name.
symbol() → string
external
#Returns the token collection symbol.
tokenURI(uint256 tokenId) → string
external
#Returns the Uniform Resource Identifier (URI) for tokenId token.
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";Implementation of the IERC721Receiver interface.
Accepts all token transfers.
Make sure the contract is able to use its token with IERC721.safeTransferFrom, IERC721.approve or
IERC721.setApprovalForAll.
Functions
onERC721Received(address, address, uint256, bytes) → bytes4
public
#See IERC721Receiver.onERC721Received.
Always returns IERC721Receiver.onERC721Received.selector.
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Utils.sol";Library that provide common ERC-721 utility functions.
See ERC-721.
Available since v5.1.
checkOnERC721Received(address operator, address from, address to, uint256 tokenId, bytes data)
internal
#Performs an acceptance check for the provided operator by calling IERC721Receiver.onERC721Received
on the to address. The operator is generally the address that initiated the token transfer (i.e. msg.sender).
The acceptance call is not executed and treated as a no-op if the target address doesn't contain code (i.e. an EOA).
Otherwise, the recipient must implement IERC721Receiver.onERC721Received and return the acceptance magic value to accept
the transfer.