Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PersistentTokens

Hierarchy

  • PersistentTokens

Index

Constructors

constructor

  • Parameters

    • prefix: string

      A prefix to use for every key of this map

    Returns PersistentTokens

Accessors

number_of_tokens

  • get number_of_tokens(): u128
  • Get number of tokens tracked in the contract

    Basic usage example:

    Assume contract has 9450 tokens,

    const persistent_tokens = new PersistentTokens('pt')
    const tokens_length = persistent_tokens.number_of_tokens();
    log(parseInt(tokens_length)) // 9450
    
    todo

    not sure _tmap.length can represent up to u128 values

    Returns u128

    Number of tokens present in the contract in u128 format

Methods

add

  • add(tokenId: TokenId, token: Token, accountId: AccountId): Token
  • Add a new token to the contract

    Basic usage example:

    Assume we need add the token T1 to the contract, and it owns by the user with account id = alice.test.near,

    const persistent_tokens = new PersistentTokens('pt')
    const token = persistent_tokens.add('alice_23456' , T1 , "alice.test.near");
    

    Parameters

    • tokenId: TokenId

      Id of the new token

    • token: Token

      Token to be saved to the contract

    • accountId: AccountId

      ID of the account that owns the token

    Returns Token

    Saved token

burn

  • burn(tokenId: TokenId, accountId: AccountId): void
  • Burn a token from the contract

    Basic usage example:

    Assume we need burn the token with token id = alice_23456 from the contract,

    const persistent_tokens = new PersistentTokens('pt')
    persistent_tokens.burn('alice_23456' , "alice.test.near");
    

    Parameters

    • tokenId: TokenId

      Id of the token to burn

    • accountId: AccountId

      ID of the account that owns the burning token

    Returns void

get

  • get(token_id: TokenId): Token
  • Get token details of a single token

    Basic usage example:

    Assume we need to get the details of the token with token id = jenny911038,

    const persistent_tokens = new PersistentTokens('pt')
    const token = persistent_tokens.get("jenny911038");
    

    Parameters

    • token_id: TokenId

      ID of token to retrieve from _map

    Returns Token

    Token details object

has

  • has(token_id: TokenId): bool
  • Check if the relevant token exists or not

    Basic usage example:

    Assume we need to check if the token with token id = jenny911038 present in the storage,

    const persistent_tokens = new PersistentTokens('pt')
    const is_token_exists = persistent_tokens.has("jenny911038");
    

    Parameters

    • token_id: TokenId

      ID of the token to check it's exists or not

    Returns bool

    true if token exits, false if not

keys

  • keys(start: i32, end: i32): TokenId[]
  • Get the IDs of tokens saved in the provided range

    Basic usage example:

    Assume we need the IDs of first 5 tokens,

    const persistent_tokens = new PersistentTokens('pt')
    const token_ids = persistent_tokens.keys(0, 5);
    

    Parameters

    • start: i32

      Start index

    • end: i32

      End index

    Returns TokenId[]

    An array of tokenIds

remove

  • remove(tokenId: TokenId, accountId: AccountId): void
  • Remove a token from a user's token set

    Basic usage example:

    Assume we need remove the token with token id = alice_23456 from the user with account id = alice.test.near,

    const persistent_tokens = new PersistentTokens('pt')
    persistent_tokens.remove('alice_23456' , "alice.test.near");
    

    Parameters

    • tokenId: TokenId

      Id of the token to remove from

    • accountId: AccountId

      ID of the account that owns the removing token

    Returns void

supply_for_owner

  • supply_for_owner(accountId: AccountId): string
  • Get number of tokens saved in the contract for a given account

    Basic usage example:

    Assume user with account id = alice.test.near has 12 tokens in the contract,

    const persistent_tokens = new PersistentTokens('pt')
    const tokens_length_for_user = persistent_tokens.supply_for_owner("alice.test.near");
    log(tokens_length_for_user) // "12"
    

    Parameters

    • accountId: AccountId

      ID of the account to retrieve number of tokens that account owns

    Returns string

    Number of tokens present for the given account in the contract

tokens_for_owner

  • tokens_for_owner(accountId: AccountId): TokenId[]
  • Get the IDs of tokens saved in the contract for a given account/user

    Basic usage example:

    Assume we need the IDs of the tokens that user with account id = alice.test.near owns,

    const persistent_tokens = new PersistentTokens('pt')
    const token_ids_for_user = persistent_tokens.tokens_for_owner("alice.test.near");
    

    Parameters

    • accountId: AccountId

      ID of the account to retrieve token IDs of the tokens that account/user owns

    Returns TokenId[]

    An array of tokenIds that the given account/user owns

Generated using TypeDoc