151 - OZ ERC721
OpenZeppelin ERC721: Implements the popular ERC721 Non-Fungible Token Standard. The functions are:
-
balanceOf(address owner)
→uint256 balance
: Returns the number of tokens in owner's account. -
ownerOf(uint256 tokenId)
→address owner
: Returns the owner of the tokenId token. Requirements: tokenId must exist. -
transferFrom(address from, address to, uint256 tokenId)
: Transfers tokenId token from from to to. Requirements:from
cannot be the zero address.to
cannot be the zero address.tokenId
token must be owned byfrom
. If the caller is notfrom
, it must be approved to move this token by eitherapprove
orsetApprovalForAll
. Emits aTransfer
event. -
safeTransferFrom(address from, address to, uint256 tokenId)
: Safely transferstokenId
token fromfrom
toto
, checking first that contract recipients are aware of the ERC721 protocol to prevent tokens from being forever locked. Requirements:From
cannot be the zero addressTo
cannot be the zero address.tokenId
token must exist and be owned by from- If the caller is not
from
, it must be have been allowed to move this token by eitherapprove
orsetApprovalForAll
- If
to
refers to a smart contract, it must implementIERC721Receiver.onERC721Received
, which is called upon a safe transfer. Emits aTransfer
event. (The use of this function is encouraged over the related but unsafe transferFrom function.)
-
approve(address to, uint256 tokenId)
: Gives permission toto
to transfertokenId
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
tokenId
must exist. Emits anApproval
event.
-
getApproved(uint256 tokenId)
→address operator
: Returns the account approved fortokenId
token. Requirements:tokenId
must exist. -
setApprovalForAll(address operator, bool _approved)
: Approve or remove operator as an operator for the caller. Operators can calltransferFrom
orsafeTransferFrom
for any token owned by the caller. Requirements: The operator cannot be the caller. Emits anApprovalForAll
event. -
isApprovedForAll(address owner, address operator)
→bool
: Returns if the operator is allowed to manage all of the assets of owner.
The different extensions/presets/utilities are:
-
OpenZeppelin ERC721Burnable: ERC721 Token that can be irreversibly burned (destroyed).
-
OpenZeppelin ERC721Enumerable: This implements an optional extension of ERC721 defined in the EIP that adds enumerability of all the token ids in the contract as well as all token ids owned by each account.
-
OpenZeppelin ERC721Pausable: ERC721 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.
-
OpenZeppelin ERC721URIStorage: ERC721 token with storage based token URI management.
-
OpenZeppelin ERC721PresetMinterPauserAutoId: ERC721 token, including:
- Ability for holders to
burn
(destroy) their tokens - A
minter
role that allows for token minting (creation) - A
pauser
role that allows to stop all token transfers - Token ID and URI autogeneration. This contract uses
AccessControl
to lock permissioned functions using the different roles. The account that deploys the contract will be granted theminter
andpauser
roles, as well as the defaultadmin
role, which will let it grant bothminter
andpauser
roles to other accounts.
- Ability for holders to
-
OpenZeppelin ERC721Holder: Implementation of the IERC721Receiver interface. Accepts all token transfers.
- ERC721 Token Standard -> NFTs
- All Required Functions
- Diffs with ERC20
- Transfers/Approvals/Operators
- Extensions/Presets/Utils