NonFungibleToken
This module provides the full NonFungibleToken module API.
| For an overview of the module, read the NonFungibleToken guide. |
Core
NonFungibleToken
import "./node_modules/@openzeppelin-compact/contracts/src/token/NonFungibleToken";
initialize(name_: Opaque<"string">, symbol_: Opaque<"string">) → [] circuit
Initializes the contract by setting the name and symbol.
This MUST be called in the implementing contract’s constructor. Failure to do so can lead to an irreparable contract.
Requirements:
-
Contract is not initialized.
Constraints:
-
k=10, rows=65
balanceOf(owner: Either<ZswapCoinPublicKey, ContractAddress>) → Uint<128> circuit
Returns the number of tokens in owner's account.
Requirements:
-
Contract is initialized.
Constraints:
-
k=10, rows=309
ownerOf(tokenId: Uint<128>) → Either<ZswapCoinPublicKey, ContractAddress> circuit
Returns the owner of the tokenId token.
Requirements:
-
The contract is initialized.
-
The
tokenIdmust exist.
Constraints:
-
k=10, rows=290
name() → Opaque<"string"> circuit
Returns the token name.
Requirements:
-
Contract is initialized.
Constraints:
-
k=10, rows=36
symbol() → Opaque<"string"> circuit
Returns the symbol of the token.
Requirements:
-
Contract is initialized.
Constraints:
-
k=10, rows=36
tokenURI(tokenId: Uint<128>) → Opaque<"string"> circuit
Returns the token URI for the given tokenId.
Returns an empty string if a tokenURI does not exist.
Requirements:
-
The contract is initialized.
-
The
tokenIdmust exist.
| Native strings and string operations aren’t supported within the Compact language, e.g. concatenating a base URI + token ID is not possible like in other NFT implementations. Therefore, we propose the URI storage approach; whereby, NFTs may or may not have unique "base" URIs. It’s up to the implementation to decide on how to handle this. |
Constraints:
-
k=10, rows=296
_setTokenURI(tokenId: Uint<128>, tokenURI: Opaque<"string">) → [] circuit
Sets the the URI as tokenURI for the given tokenId.
Requirements:
-
The contract is initialized.
-
The
tokenIdmust exist.
| The URI for a given NFT is usually set when the NFT is minted. |
Constraints:
-
k=10, rows=253
approve(to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
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.
Requirements:
-
The contract is initialized.
-
The caller must either own the token or be an approved operator.
-
tokenIdmust exist.
Constraints:
-
k=10, rows=966
getApproved(tokenId: Uint<128>) → Either<ZswapCoinPublicKey, ContractAddress> circuit
Returns the account approved for tokenId token.
Requirements:
-
The contract is initialized.
-
tokenIdmust exist.
Constraints:
-
k=10, rows=409
setApprovalForAll(operator: Either<ZswapCoinPublicKey, ContractAddress>, approved: Boolean) → [] circuit
Approve or remove operator as an operator for the caller.
Operators can call transferFrom for any token owned by the caller.
Requirements:
-
The contract is initialized.
-
The
operatorcannot be the zero address.
Constraints:
-
k=10, rows=409
isApprovedForAll(owner: Either<ZswapCoinPublicKey, ContractAddress>, operator: Either<ZswapCoinPublicKey, ContractAddress>) → Boolean circuit
Returns if the operator is allowed to manage all of the assets of owner.
Requirements:
-
The contract must have been initialized.
Constraints:
-
k=10, rows=621
transferFrom(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
Transfers tokenId token from from to to.
| Transfers to contract addresses are currently disallowed until contract-to-contract interactions are supported in Compact. This restriction prevents assets from being inadvertently locked in contracts that cannot currently handle token receipt. |
Requirements:
-
The contract is initialized.
-
fromis not the zero address. -
tois not the zero address. -
tois not a ContractAddress. -
tokenIdtoken must be owned byfrom. -
If the caller is not
from, it must be approved to move this token by either approve or setApprovalForAll.
Constraints:
-
k=11, rows=1966
_unsafeTransferFrom(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
Unsafe variant of transferFrom which allows transfers to contract addresses.
| Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported. Tokens sent to a contract address may become irretrievable. Once contract-to-contract calls are supported, this circuit may be deprecated. |
Requirements:
-
The contract is initialized.
-
fromis not the zero address. -
tois not the zero address. -
tokenIdtoken must be owned byfrom. -
If the caller is not
from, it must be approved to move this token by either approve or setApprovalForAll.
Constraints:
-
k=11, rows=1963
_ownerOf(tokenId: Uint<128>) → Either<ZswapCoinPublicKey, ContractAddress> circuit
Returns the owner of the tokenId. Does NOT revert if token doesn’t exist
Requirements:
-
The contract is initialized.
Constraints:
-
k=10, rows=253
_getApproved(tokenId: Uint<128>) → Either<ZswapCoinPublicKey, ContractAddress> circuit
Returns the approved address for tokenId. Returns the zero address if tokenId is not minted.
Requirements:
-
The contract is initialized.
Constraints:
-
k=10, rows=253
_isAuthorized(owner: Either<ZswapCoinPublicKey, ContractAddress>, spender: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128> ) → Boolean circuit
Returns whether spender is allowed to manage owner's tokens, or tokenId in particular (ignoring whether it is owned by owner).
Requirements:
-
The contract is initialized.
This function assumes that owner is the actual owner of tokenId and does not verify this assumption.
|
Constraints:
-
k=11, rows=1098
_checkAuthorized(owner: Either<ZswapCoinPublicKey, ContractAddress>, spender: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128> ) → [] circuit
Checks if spender can operate on tokenId, assuming the provided owner is the actual owner.
Requirements:
-
The contract is initialized.
-
spenderhas approval fromownerfortokenIdORspenderhas approval to manage all of `owner’s assets.
This function assumes that owner is the actual owner of tokenId and does not verify this assumption.
|
Constraints:
-
k=11, rows=1121
_update(to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>, auth: Either<ZswapCoinPublicKey, ContractAddress>) → Either<ZswapCoinPublicKey, ContractAddress> internal
Transfers tokenId from its current owner to to, or alternatively mints (or burns) if the current owner (or to) is the zero address.
Returns the owner of the tokenId before the update.
Requirements:
-
The contract is initialized.
-
If
authis non 0, then this function will check thatauthis either the owner of the token, or approved to operate on the token (by the owner).
Constraints:
-
k=12, rows=2049
_mint(to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
Mints tokenId and transfers it to to.
Requirements:
-
The contract is initialized.
-
tokenIdmust not exist. -
tois not the zero address. -
tois not a ContractAddress.
Constraints:
-
k=10, rows=1013
_unsafeMint(account: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>) → [] circuit
Unsafe variant of _mint which allows transfers to contract addresses.
Requirements:
-
Contract is initialized.
-
tokenIdmust not exist. -
tois not the zero address.
| Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported. Tokens sent to a contract address may become irretrievable. Once contract-to-contract calls are supported, this circuit may be deprecated. |
Constraints:
-
k=10, rows=1010
_burn(tokenId: Uint<128>) → [] circuit
Destroys tokenId.
The approval is cleared when the token is burned.
This circuit does not check if the sender is authorized to operate on the token.
Requirements:
-
The contract is initialized.
-
tokenIdmust exist.
Constraints:
-
k=10, rows=479
_transfer(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
Transfers tokenId from from to to. As opposed to transferFrom, this imposes no restrictions on ownPublicKey().
| Transfers to contract addresses are currently disallowed until contract-to-contract interactions are supported in Compact. This restriction prevents assets from being inadvertently locked in contracts that cannot currently handle token receipt. |
Requirements:
-
The contract is initialized.
-
tois not the zero address. -
tois not a ContractAddress. -
tokenIdtoken must be owned byfrom.
Constraints:
-
k=11, rows=1224
_unsafeTransfer(from: Either<ZswapCoinPublicKey, ContractAddress>, to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>) → [] circuit
Unsafe variant of _transfer which allows transfers to contract addresses.
Transfers tokenId from from to to. As opposed to _unsafeTransferFrom, this imposes no restrictions on ownPublicKey(). It does NOT check if the recipient is a ContractAddress.
| Transfers to contract addresses are considered unsafe because contract-to-contract calls are not currently supported. Tokens sent to a contract address may become irretrievable. Once contract-to-contract calls are supported, this circuit may be deprecated. |
Requirements:
-
Contract is initialized.
-
tois not the zero address. -
tokenIdtoken must be owned byfrom.
Constraints:
-
k=11, rows=1221
_approve(to: Either<ZswapCoinPublicKey, ContractAddress>, tokenId: Uint<128>, auth: Either<ZswapCoinPublicKey, ContractAddress>) → [] circuit
Approve to to operate on tokenId
Requirements:
-
The contract is initialized.
-
If
authis non 0, then this function will check thatauthis either the owner of the token, or approved to operate on the token (by the owner).
Constraints:
-
k=11, rows=1109
_setApprovalForAll(owner: Either<ZswapCoinPublicKey, ContractAddress>, operator: Either<ZswapCoinPublicKey, ContractAddress>, approved: Boolean) → [] circuit
Approve operator to operate on all of owner tokens
Requirements:
-
The contract is initialized.
-
operatoris not the zero address.
Constraints:
-
k=10, rows=524