pub struct NonFungibleToken {
    pub owner_id: AccountId,
    pub extra_storage_in_bytes_per_token: StorageUsage,
    pub owner_by_id: TreeMap<TokenId, AccountId>,
    pub token_metadata_by_id: Option<LookupMap<TokenId, TokenMetadata>>,
    pub tokens_per_owner: Option<LookupMap<AccountId, UnorderedSet<TokenId>>>,
    pub approvals_by_id: Option<LookupMap<TokenId, HashMap<AccountId, u64>>>,
    pub next_approval_id_by_id: Option<LookupMap<TokenId, u64>>,
}
Expand description

Implementation of the non-fungible token standard. Allows to include NEP-171 compatible token to any contract. There are next traits that any contract may implement: - NonFungibleTokenCore – interface with nft_transfer methods. NonFungibleToken provides methods for it. - NonFungibleTokenApproval – interface with nft_approve methods. NonFungibleToken provides methods for it. - NonFungibleTokenEnumeration – interface for getting lists of tokens. NonFungibleToken provides methods for it. - NonFungibleTokenMetadata – return metadata for the token in NEP-177, up to contract to implement.

For example usage, see examples/non-fungible-token/src/lib.rs.

Fields§

§owner_id: AccountId§extra_storage_in_bytes_per_token: StorageUsage§owner_by_id: TreeMap<TokenId, AccountId>§token_metadata_by_id: Option<LookupMap<TokenId, TokenMetadata>>§tokens_per_owner: Option<LookupMap<AccountId, UnorderedSet<TokenId>>>§approvals_by_id: Option<LookupMap<TokenId, HashMap<AccountId, u64>>>§next_approval_id_by_id: Option<LookupMap<TokenId, u64>>

Implementations§

source§

impl NonFungibleToken

source

pub fn new<Q, R, S, T>( owner_by_id_prefix: Q, owner_id: AccountId, token_metadata_prefix: Option<R>, enumeration_prefix: Option<S>, approval_prefix: Option<T> ) -> Self

source

pub fn internal_transfer_unguarded( &mut self, token_id: &TokenId, from: &AccountId, to: &AccountId )

Transfer token_id from from to to

Do not perform any safety checks or do any logging

source

pub fn internal_transfer( &mut self, sender_id: &AccountId, receiver_id: &AccountId, token_id: &TokenId, approval_id: Option<u64>, memo: Option<String> ) -> (AccountId, Option<HashMap<AccountId, u64>>)

Transfer from current owner to receiver_id, checking that sender is allowed to transfer. Clear approvals, if approval extension being used. Return previous owner and approvals.

source

pub fn mint( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata> ) -> Token

👎Deprecated since 4.0.0: mint is deprecated, please use internal_mint instead.

Mint a new token. Not part of official standard, but needed in most situations. Consuming contract expected to wrap this with an nft_mint function.

Requirements:

  • Caller must be the owner_id set during contract initialization.
  • Caller of the method must attach a deposit of 1 yoctoⓃ for security purposes.
  • If contract is using Metadata extension (by having provided metadata_prefix during contract initialization), token_metadata must be given.
  • token_id must be unique

Returns the newly minted token

source

pub fn internal_mint( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata> ) -> Token

Mint a new token without checking:

  • Whether the caller id is equal to the owner_id
  • Assumes there will be a refund to the predecessor after covering the storage costs

Returns the newly minted token and emits the mint event

source

pub fn internal_mint_with_refund( &mut self, token_id: TokenId, token_owner_id: AccountId, token_metadata: Option<TokenMetadata>, refund_id: Option<AccountId> ) -> Token

Mint a new token without checking:

  • Whether the caller id is equal to the owner_id
  • refund_id will transfer the left over balance after storage costs are calculated to the provided account. Typically the account will be the owner. If None, will not refund. This is useful for delaying refunding until multiple tokens have been minted.

Returns the newly minted token and does not emit the mint event. This allows minting multiple before emitting.

Trait Implementations§

source§

impl BorshDeserialize for NonFungibleToken

source§

fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self, Error>

source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

source§

impl BorshSerialize for NonFungibleToken

source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

source§

impl NonFungibleTokenApproval for NonFungibleToken

source§

fn nft_approve( &mut self, token_id: TokenId, account_id: AccountId, msg: Option<String> ) -> Option<Promise>

Add an approved account for a specific token. Read more
source§

fn nft_revoke(&mut self, token_id: TokenId, account_id: AccountId)

Revoke an approved account for a specific token. Read more
source§

fn nft_revoke_all(&mut self, token_id: TokenId)

Revoke all approved accounts for a specific token. Read more
source§

fn nft_is_approved( &self, token_id: TokenId, approved_account_id: AccountId, approval_id: Option<u64> ) -> bool

Check if a token is approved for transfer by a given account, optionally checking an approval_id Read more
source§

impl NonFungibleTokenCore for NonFungibleToken

source§

fn nft_transfer( &mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String> )

Simple transfer. Transfer a given token_id from current owner to receiver_id. Read more
source§

fn nft_transfer_call( &mut self, receiver_id: AccountId, token_id: TokenId, approval_id: Option<u64>, memo: Option<String>, msg: String ) -> PromiseOrValue<bool>

Transfer token and call a method on a receiver contract. A successful workflow will end in a success execution outcome to the callback on the NFT contract at the method nft_resolve_transfer. Read more
source§

fn nft_token(&self, token_id: TokenId) -> Option<Token>

Returns the token with the given token_id or null if no such token.
source§

impl NonFungibleTokenEnumeration for NonFungibleToken

source§

fn nft_total_supply(&self) -> U128

Returns the total supply of non-fungible tokens as a string representing an unsigned 128-bit integer to avoid JSON number limit of 2^53.
source§

fn nft_tokens(&self, from_index: Option<U128>, limit: Option<u64>) -> Vec<Token>

Get a list of all tokens Read more
source§

fn nft_supply_for_owner(&self, account_id: AccountId) -> U128

Get number of tokens owned by a given account Read more
source§

fn nft_tokens_for_owner( &self, account_id: AccountId, from_index: Option<U128>, limit: Option<u64> ) -> Vec<Token>

Get list of all tokens owned by a given account Read more
source§

impl NonFungibleTokenResolver for NonFungibleToken

source§

fn nft_resolve_transfer( &mut self, previous_owner_id: AccountId, receiver_id: AccountId, token_id: TokenId, approved_account_ids: Option<HashMap<AccountId, u64>> ) -> bool

Returns true if token was successfully transferred to receiver_id.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.