Skip to content

Latest commit

 

History

History
379 lines (253 loc) · 9.39 KB

erc721a-upgradeable.mdx

File metadata and controls

379 lines (253 loc) · 9.39 KB

ERC721AUpgradeable

erc721a-upgradeable/contracts/ERC721AUpgradeable.sol

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 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 by from.
  • If the caller is not from, it must be approved to move this token by either approve or setApprovalForAll.

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 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 by from.
  • If the caller is not from, it must be approved to move this token by either approve or setApprovalForAll.
  • If to refers to a smart contract, it must implement IERC721Receiver.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 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.

setApprovalForAll

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.

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 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:

  • tokenId must 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:

  • tokenId must 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.