erc721a-upgradeable/contracts/ERC721AUpgradeable.sol
NFT contract base implementation.
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
.
function transferFrom(
address from,
address to,
uint256 tokenId
) public virtual override
Transfers tokenId
token from from
to to
.
Calling conditions:
from
cannot be the zero address.to
cannot be the zero address.tokenId
token must be owned byfrom
.- If the caller is not
from
, it must be approved to move this token by eitherapprove
orsetApprovalForAll
.
Emits a Transfer
event.
Params: | |
---|---|
from |
The source address. |
to |
The destination address. |
tokenId |
The token ID to transfer. |
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public virtual override
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.
The data
parameter is forwarded in IERC721Receiver.onERC721Received
to contract recipients (optional, default: ""
).
Calling conditions:
from
cannot be the zero address.to
cannot be the zero address.tokenId
token must be owned byfrom
.- If the caller is not
from
, it must be approved 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 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. |
function approve(address to, uint256 tokenId) public override
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.
Calling conditions:
- The caller must own the token or be an approved operator.
tokenId
must exist.
Emits an Approval
event.
Params: | |
---|---|
to |
The address to approve. |
tokenId |
The token ID to approve for. |
function setApprovalForAll(
address operator,
bool approved
) public virtual override
Approve 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
operator
cannot be the caller.
Emits an ApprovalForAll
event.
Params: | |
---|---|
operator |
The operator's address. |
approved |
Whether the operator is approved. |
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 to learn more about how these ids are created.
Params: | |
---|---|
interfaceId |
The 4 byte interface ID. |
function totalSupply() public view returns (uint256)
Returns the total number of tokens in existence.
Burned tokens will reduce the count.
function balanceOf(address owner) public view override returns (uint256)
Returns the number of tokens in owner
's account.
Params: | |
---|---|
owner |
The owner to query. |
function ownerOf(uint256 tokenId) public view override returns (address)
Returns the owner of the tokenId
token.
Calling conditions:
tokenId
must exist.
Params: | |
---|---|
tokenId |
The token ID. |
function name() public view virtual override returns (string memory)
Returns the token collection name.
function symbol() public view virtual override returns (string memory)
Returns the token collection symbol.
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. |
function getApproved(uint256 tokenId) public view override returns (address)
Returns the account approved for tokenId
token.
Calling conditions:
tokenId
must exist.
Params: | |
---|---|
tokenId |
The token ID. |
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. |
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. |
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. |
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 . |
error ApprovalCallerNotOwnerNorApproved()
The caller must own the token or be an approved operator.
error ApprovalQueryForNonexistentToken()
The token does not exist.
error BalanceQueryForZeroAddress()
Cannot query the balance for the zero address.
error MintToZeroAddress()
Cannot mint to the zero address.
error MintZeroQuantity()
The quantity of tokens minted must be more than zero.
error OwnerQueryForNonexistentToken()
The token does not exist.
error TransferCallerNotOwnerNorApproved()
The caller must own the token or be an approved operator.
error TransferFromIncorrectOwner()
The token must be owned by from
.
error TransferToNonERC721ReceiverImplementer()
Cannot safely transfer to a contract that does not implement the ERC721Receiver interface.
error TransferToZeroAddress()
Cannot transfer to the zero address.
error URIQueryForNonexistentToken()
The token does not exist.