ERC721AUpgradeable
erc721a-upgradeable/contracts/ERC721AUpgradeable.sol (opens in a new tab)
NFT contract base implementation.
Structs
TokenOwnership
struct TokenOwnership {
// The address of the owner.
address addr;
// Keeps track of the start time of ownership with minimal overhead for tokenomics.
uint64 startTimestamp;
// Whether the token has been burned.
bool burned;
}Holds ownership data for each token.
startTimestamp is the timestamp when the token is minted to, transferred to, or burned by addr.
Write Functions
transferFrom
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual overrideTransfers tokenId token from from to to.
Calling conditions:
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 eitherapproveorsetApprovalForAll.
Emits a Transfer event.
| Params: | |
|---|---|
from | The source address. |
to | The destination address. |
tokenId | The token ID to transfer. |
safeTransferFrom
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual overrideSafely 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.
The data parameter is forwarded in IERC721Receiver.onERC721Received to contract recipients (optional, default: "").
Calling conditions:
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 eitherapproveorsetApprovalForAll. - If
torefers to a smart contract, it must implementIERC721Receiver.onERC721Received, which is called upon a safe transfer.
Emits a Transfer event.
| Params: | |
|---|---|
from | The source address. |
to | The destination address. |
tokenId | The token ID to transfer. |
_data | Optional data to be passed into the IERC721Receiver.onERC721Received function of the receiving contract. |
approve
function approve(address to, uint256 tokenId) public overrideGives 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.
Calling conditions:
- The caller must own the token or be an approved operator.
tokenIdmust exist.
Emits an Approval event.
| Params: | |
|---|---|
to | The address to approve. |
tokenId | The token ID to approve for. |
setApprovalForAll
function setApprovalForAll(
address operator,
bool approved
) public virtual overrideApprove or remove operator as an operator for the caller. Operators can call transferFrom or safeTransferFrom for any token owned by the caller.
Calling conditions:
- The
operatorcannot be the caller.
Emits an ApprovalForAll event.
| Params: | |
|---|---|
operator | The operator's address. |
approved | Whether the operator is approved. |
Read-only Functions
supportsInterface
IERC165-supportsInterface
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)Returns true if this contract implements the interface defined by interfaceId.
See the corresponding EIP section (opens in a new tab) to learn more about how these ids are created.
| Params: | |
|---|---|
interfaceId | The 4 byte interface ID. |
totalSupply
function totalSupply() public view returns (uint256)Returns the total number of tokens in existence.
Burned tokens will reduce the count.
balanceOf
function balanceOf(address owner) public view override returns (uint256)Returns the number of tokens in owner's account.
| Params: | |
|---|---|
owner | The owner to query. |
ownerOf
function ownerOf(uint256 tokenId) public view override returns (address)Returns the owner of the tokenId token.
Calling conditions:
tokenIdmust exist.
| Params: | |
|---|---|
tokenId | The token ID. |
name
function name() public view virtual override returns (string memory)Returns the token collection name.
symbol
function symbol() public view virtual override returns (string memory)Returns the token collection symbol.
tokenURI
function tokenURI(uint256 tokenId) public view virtual override returns (string memory)Returns the Uniform Resource Identifier (URI) for tokenId token.
| Params: | |
|---|---|
tokenId | The token ID. |
getApproved
function getApproved(uint256 tokenId) public view override returns (address)Returns the account approved for tokenId token.
Calling conditions:
tokenIdmust exist.
| Params: | |
|---|---|
tokenId | The token ID. |
isApprovedForAll
function isApprovedForAll(
address owner,
address operator
) public view virtual override returns (bool)Returns if the operator is allowed to manage all of the assets of owner.
| Params: | |
|---|---|
owner | The owner of tokens. |
operator | The operator. |
Events
Transfer
event Transfer(address from, address to, uint256 tokenId)Emitted when tokenId token is transferred from from to to.
| Params: | |
|---|---|
from | The previous owner of tokenId. |
to | The new owner of tokenId. |
tokenId | The token ID. |
Approval
event Approval(address owner, address approved, uint256 tokenId)Emitted when owner enables approved to manage the tokenId token.
| Params: | |
|---|---|
owner | The owner of tokenId. |
approved | The approved address. |
tokenId | The token ID. |
ApprovalForAll
event ApprovalForAll(address owner, address operator, bool approved)Emitted when owner enables or disables (approved) operator to manage all of its assets.
| Params: | |
|---|---|
owner | The owner. |
operator | The approved operator. |
approved | Whether the operator is approved to operate all the tokens of owner. |
Errors
ApprovalCallerNotOwnerNorApproved
error ApprovalCallerNotOwnerNorApproved()The caller must own the token or be an approved operator.
ApprovalQueryForNonexistentToken
error ApprovalQueryForNonexistentToken()The token does not exist.
BalanceQueryForZeroAddress
error BalanceQueryForZeroAddress()Cannot query the balance for the zero address.
MintToZeroAddress
error MintToZeroAddress()Cannot mint to the zero address.
MintZeroQuantity
error MintZeroQuantity()The quantity of tokens minted must be more than zero.
OwnerQueryForNonexistentToken
error OwnerQueryForNonexistentToken()The token does not exist.
TransferCallerNotOwnerNorApproved
error TransferCallerNotOwnerNorApproved()The caller must own the token or be an approved operator.
TransferFromIncorrectOwner
error TransferFromIncorrectOwner()The token must be owned by from.
TransferToNonERC721ReceiverImplementer
error TransferToNonERC721ReceiverImplementer()Cannot safely transfer to a contract that does not implement the ERC721Receiver interface.
TransferToZeroAddress
error TransferToZeroAddress()Cannot transfer to the zero address.
URIQueryForNonexistentToken
error URIQueryForNonexistentToken()The token does not exist.