Sound Protocol
Libraries
Erc721a Upgradeable

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 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:
fromThe source address.
toThe destination address.
tokenIdThe 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:
fromThe source address.
toThe destination address.
tokenIdThe token ID to transfer.
_dataOptional 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:
toThe address to approve.
tokenIdThe 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:
operatorThe operator's address.
approvedWhether 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:
interfaceIdThe 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:
ownerThe 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:
tokenIdThe 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:
tokenIdThe 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:
tokenIdThe 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:
ownerThe owner of tokens.
operatorThe operator.

Events

Transfer

event Transfer(address from, address to, uint256 tokenId)

Emitted when tokenId token is transferred from from to to.

Params:
fromThe previous owner of tokenId.
toThe new owner of tokenId.
tokenIdThe token ID.

Approval

event Approval(address owner, address approved, uint256 tokenId)

Emitted when owner enables approved to manage the tokenId token.

Params:
ownerThe owner of tokenId.
approvedThe approved address.
tokenIdThe 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:
ownerThe owner.
operatorThe approved operator.
approvedWhether 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.