pub struct FungibleToken {
    pub accounts: LookupMap<AccountId, Balance>,
    pub total_supply: Balance,
    pub account_storage_usage: StorageUsage,
}
Expand description

Implementation of a FungibleToken standard. Allows to include NEP-141 compatible token to any contract. There are next traits that any contract may implement: - FungibleTokenCore – interface with ft_transfer methods. FungibleToken provides methods for it. - FungibleTokenMetaData – return metadata for the token in NEP-148, up to contract to implement. - StorageManager – interface for NEP-145 for allocating storage per account. FungibleToken provides methods for it. - AccountRegistrar – interface for an account to register and unregister

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

Fields§

§accounts: LookupMap<AccountId, Balance>

AccountID -> Account balance.

§total_supply: Balance

Total supply of the all token.

§account_storage_usage: StorageUsage

The storage size in bytes for one account.

Implementations§

Internal method that returns the amount of burned tokens in a corner case when the sender has deleted (unregistered) their account while the ft_transfer_call was still in flight. Returns (Used token amount, Burned token amount)

Internal method that returns the Account ID and the balance in case the account was unregistered.

Trait Implementations§

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Deserialize this instance from a slice of bytes.
Serialize this instance into a vector of bytes.
Transfers positive amount of tokens from the env::predecessor_account_id to receiver_id. Both accounts must be registered with the contract for transfer to succeed. (See NEP-145) This method must to be able to accept attached deposits, and must not panic on attached deposit. Exactly 1 yoctoNEAR must be attached. See the Security section of the standard. Read more
Transfers positive amount of tokens from the env::predecessor_account_id to receiver_id account. Then calls ft_on_transfer method on receiver_id contract and attaches a callback to resolve this transfer. ft_on_transfer method must return the amount of tokens unused by the receiver contract, the remaining tokens must be refunded to the predecessor_account_id at the resolve transfer callback. Read more
Returns the total supply of the token in a decimal string representation.
Returns the balance of the account. If the account doesn’t exist must returns "0".

While storage_withdraw normally allows the caller to retrieve available balance, the basic Fungible Token implementation sets storage_balance_bounds.min == storage_balance_bounds.max, which means available balance will always be 0. So this implementation:

  • panics if amount > 0
  • never transfers Ⓝ to caller
  • returns a storage_balance struct if amount is 0
Unregisters the predecessor account and returns the storage NEAR deposit back. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.