ERC721Upgradeable.sol
View Source: @openzeppelin\contracts-upgradeable\token\ERC721\ERC721Upgradeable.sol
↗ Extends: Initializable, ContextUpgradeable, ERC165Upgradeable, IERC721Upgradeable, IERC721MetadataUpgradeable ↘ Derived Contracts: ERC721BurnableUpgradeable, ERC721EnumerableUpgradeable, ERC721URIStorageUpgradeable
ERC721Upgradeable
Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including the Metadata extension, but not including the Enumerable extension, which is available separately as {ERC721Enumerable}.
Contract Members
Constants & Variables
string private _name;
string private _symbol;
mapping(uint256 => address) private _owners;
mapping(address => uint256) private _balances;
mapping(uint256 => address) private _tokenApprovals;
mapping(address => mapping(address => bool)) private _operatorApprovals;
uint256[44] private __gap;
Functions
- _ERC721_init(string name, string symbol_)
- _ERC721_init_unchained(string name, string symbol_)
- supportsInterface(bytes4 interfaceId)
- balanceOf(address owner)
- ownerOf(uint256 tokenId)
- name()
- symbol()
- tokenURI(uint256 tokenId)
- _baseURI()
- approve(address to, uint256 tokenId)
- getApproved(uint256 tokenId)
- setApprovalForAll(address operator, bool approved)
- isApprovedForAll(address owner, address operator)
- transferFrom(address from, address to, uint256 tokenId)
- safeTransferFrom(address from, address to, uint256 tokenId)
- safeTransferFrom(address from, address to, uint256 tokenId, bytes _data)
- _safeTransfer(address from, address to, uint256 tokenId, bytes _data)
- _exists(uint256 tokenId)
- _isApprovedOrOwner(address spender, uint256 tokenId)
- _safeMint(address to, uint256 tokenId)
- _safeMint(address to, uint256 tokenId, bytes _data)
- _mint(address to, uint256 tokenId)
- _burn(uint256 tokenId)
- _transfer(address from, address to, uint256 tokenId)
- _approve(address to, uint256 tokenId)
- _setApprovalForAll(address owner, address operator, bool approved)
- _checkOnERC721Received(address from, address to, uint256 tokenId, bytes _data)
- _beforeTokenTransfer(address from, address to, uint256 tokenId)
- _afterTokenTransfer(address from, address to, uint256 tokenId)
__ERC721_init
Initializes the contract by setting a name and a symbol to the token collection.
function __ERC721_init(string name_, string symbol_) internal nonpayable onlyInitializing
Arguments
| Name | Type | Description |
|---|---|---|
| name_ | string | |
| symbol_ | string |
__ERC721_init_unchained
function __ERC721_init_unchained(string name_, string symbol_) internal nonpayable onlyInitializing
Arguments
| Name | Type | Description |
|---|---|---|
| name_ | string | |
| symbol_ | string |
supportsInterface
See {IERC165-supportsInterface}.
function supportsInterface(bytes4 interfaceId) public view
returns(bool)
Arguments
| Name | Type | Description |
|---|---|---|
| interfaceId | bytes4 |
balanceOf
See {IERC721-balanceOf}.
function balanceOf(address owner) public view
returns(uint256)
Arguments
| Name | Type | Description |
|---|---|---|
| owner | address |
ownerOf
See {IERC721-ownerOf}.
function ownerOf(uint256 tokenId) public view
returns(address)
Arguments
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 |
name
See {IERC721Metadata-name}.
function name() public view
returns(string)
Arguments
| Name | Type | Description | | ————- |————- | —–|
symbol
See {IERC721Metadata-symbol}.
function symbol() public view
returns(string)
Arguments
| Name | Type | Description | | ————- |————- | —–|
tokenURI
See {IERC721Metadata-tokenURI}.
function tokenURI(uint256 tokenId) public view
returns(string)
Arguments
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 |
_baseURI
Base URI for computing {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.
function _baseURI() internal view
returns(string)
Arguments
| Name | Type | Description | | ————- |————- | —–|
approve
See {IERC721-approve}.
function approve(address to, uint256 tokenId) public nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| to | address | |
| tokenId | uint256 |
getApproved
See {IERC721-getApproved}.
function getApproved(uint256 tokenId) public view
returns(address)
Arguments
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 |
setApprovalForAll
See {IERC721-setApprovalForAll}.
function setApprovalForAll(address operator, bool approved) public nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| operator | address | |
| approved | bool |
isApprovedForAll
See {IERC721-isApprovedForAll}.
function isApprovedForAll(address owner, address operator) public view
returns(bool)
Arguments
| Name | Type | Description |
|---|---|---|
| owner | address | |
| operator | address |
transferFrom
See {IERC721-transferFrom}.
function transferFrom(address from, address to, uint256 tokenId) public nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 |
safeTransferFrom
See {IERC721-safeTransferFrom}.
function safeTransferFrom(address from, address to, uint256 tokenId) public nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 |
safeTransferFrom
See {IERC721-safeTransferFrom}.
function safeTransferFrom(address from, address to, uint256 tokenId, bytes _data) public nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 | |
| _data | bytes |
_safeTransfer
Safely transfers tokenId token from from to to, checking first that contract recipients
are aware of the ERC721 protocol 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 equivalent to {safeTransferFrom}, and can be used to e.g.
implement alternative mechanisms to perform token transfer, such as signature-based.
Requirements:
fromcannot be the zero address.tocannot be the zero address.tokenIdtoken must exist and be owned byfrom.- If
torefers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event.
function _safeTransfer(address from, address to, uint256 tokenId, bytes _data) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 | |
| _data | bytes |
_exists
Returns whether tokenId exists.
Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
Tokens start existing when they are minted (_mint),
and stop existing when they are burned (_burn).
function _exists(uint256 tokenId) internal view
returns(bool)
Arguments
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 |
_isApprovedOrOwner
Returns whether spender is allowed to manage tokenId.
Requirements:
tokenIdmust exist.
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view
returns(bool)
Arguments
| Name | Type | Description |
|---|---|---|
| spender | address | |
| tokenId | uint256 |
_safeMint
Safely mints tokenId and transfers it to to.
Requirements:
tokenIdmust not exist.- If
torefers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. Emits a {Transfer} event.
function _safeMint(address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| to | address | |
| tokenId | uint256 |
_safeMint
Same as {xref-ERC721-_safeMint-address-uint256-}[_safeMint], with an additional data parameter which is
forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
function _safeMint(address to, uint256 tokenId, bytes _data) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| to | address | |
| tokenId | uint256 | |
| _data | bytes |
_mint
Mints tokenId and transfers it to to.
WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
Requirements:
tokenIdmust not exist.tocannot be the zero address. Emits a {Transfer} event.
function _mint(address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| to | address | |
| tokenId | uint256 |
_burn
Destroys tokenId.
The approval is cleared when the token is burned.
Requirements:
tokenIdmust exist. Emits a {Transfer} event.
function _burn(uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| tokenId | uint256 |
_transfer
Transfers tokenId from from to to.
As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
Requirements:
tocannot be the zero address.tokenIdtoken must be owned byfrom. Emits a {Transfer} event.
function _transfer(address from, address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 |
_approve
Approve to to operate on tokenId
Emits a {Approval} event.
function _approve(address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| to | address | |
| tokenId | uint256 |
_setApprovalForAll
Approve operator to operate on all of owner tokens
Emits a {ApprovalForAll} event.
function _setApprovalForAll(address owner, address operator, bool approved) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| owner | address | |
| operator | address | |
| approved | bool |
_checkOnERC721Received
Internal function to invoke {IERC721Receiver-onERC721Received} on a target address. The call is not executed if the target address is not a contract.
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes _data) private nonpayable
returns(bool)
Returns
bool whether the call correctly returned the expected magic value
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | address representing the previous owner of the given token ID |
| to | address | target address that will receive the tokens |
| tokenId | uint256 | uint256 ID of the token to be transferred |
| _data | bytes | bytes optional data to send along with the call |
_beforeTokenTransfer
Hook that is called before any token transfer. This includes minting and burning. Calling conditions:
- When
fromandtoare both non-zero,from’stokenIdwill be transferred toto. - When
fromis zero,tokenIdwill be minted forto. - When
tois zero,from’stokenIdwill be burned. fromandtoare never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 |
_afterTokenTransfer
Hook that is called after any transfer of tokens. This includes minting and burning. Calling conditions:
- when
fromandtoare both non-zero. fromandtoare never both zero. To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
function _afterTokenTransfer(address from, address to, uint256 tokenId) internal nonpayable
Arguments
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| tokenId | uint256 |
Contracts
- ActivateToken
- AddressUpgradeable
- ContextUpgradeable
- CreatorToken
- CustomToken
- ERC165Upgradeable
- ERC20Upgradeable
- ERC721BurnableUpgradeable
- ERC721EnumerableUpgradeable
- ERC721Upgradeable
- ERC721URIStorageUpgradeable
- IERC165Upgradeable
- IERC20MetadataUpgradeable
- IERC20Upgradeable
- IERC721EnumerableUpgradeable
- IERC721MetadataUpgradeable
- IERC721ReceiverUpgradeable
- IERC721Upgradeable
- ImmutableEntity
- ImmutableProduct
- Initializable
- Migrations
- OwnableUpgradeable
- ProductActivate
- StringCommon
- StringsUpgradeable