NFT & MarketplacesBe mindful of not confusing an NFT with an NFT-marketplace. NFT simply store information (metadata), while NFT-marketplaces are contracts where NFT can be listed and exchanged for a price.
NEP-171 (NFT Interface)
NEP-171 is the blueprint for all non-fungible tokens on NEAR. It defines a common set of rules and functions that the contract MUST implement to be considered a non-fungible token contract.Interface
nft_token (read-only)
Returns the token information for a given token_id
nft_transfer
Transfers the token_id from the caller to the receiver_id, optionally the function can include a memo field to provide additional information to the contract
The caller must be the either the current owner of the token or an account that has been approved to transfer the token on behalf of the owner, such as a marketplace contract. The approval mechanism is defined in the NEP-178 standard.
Requirement: The caller must attach exactly 1 yoctoNEAR to the call
nft_transfer_call
The function transfers the token_id to the receiver_id and calls the method nft_on_transfer(sender_id, previous_owner_id, token_id, msg) on receiver_id.
Optionally the function can include a memo for the NFT contract, and a msg field to which will be sent to the receiver contract.
📖 This function is useful to transfer NFTs to a contract and trigger some action on the receiver side in a single transaction, thus acting as attaching NFTs to a function call
nft_on_transfer
nft_on_transfer
Smart contracts expecting to receive Non-Fungible Tokens must implement this method.The method must return a boolean value indicating whether the token should be returned to the sender (⚠️ Note that this method does not need to be implemented by the NFT contract itself, but rather by any contract that expects to receive non-fungible tokens
true) or not (false).nft_resolve_transfer
This method is used as a callback to resolve the nft_transfer_call transaction, handling refunds if necessary.
It must return true if the token was successfully transferred to receiver_id, or false if the token was returned to owner_id.
NEP-177 (NFT Metadata)
NEP-177 is an extension to the NEP-171 standard that defines the metadata for both non-fungible tokens and non-fungible token contracts. Metadata provides key information , such as the contract’s name or the NFT’s title. Particularly, the following fields MUST be included in the smart contract and token’s metadata:NEP-178 (NFT Approval Management)
NEP-178 is an extension to the NEP-171 standard that defines the approval management for non-fungible tokens. The approval mechanism allows the owner of an NFT to authorize another account (for example, a marketplace contract) to transfer the token on their behalf.Interface
nft_is_approved (read-only)
Returns whether an approved_account_id is actually approved to transfer the token_id on behalf of the token owner. If approval_id is provided, it will also check that the approval ID matches.
nft_approve
Grants approval to account_id to transfer the token_id on behalf of the token owner. Optionally, the function can include a msg field to provide additional information to the contract.
Requirement: The caller must attach a deposit of at least 1 yoctoNEAR plus the storage cost for adding the new approval
nft_revoke
Revokes approval for account_id to transfer the token_id on behalf of the token owner.
Requirement: The caller must attach exactly 1 yoctoNEAR to the call
nft_revoke_all
Revokes all approvals for the token_id.
Requirement: The caller must attach exactly 1 yoctoNEAR to the call