Token

public class Token : Codable, CustomStringConvertible
extension Token: Equatable
extension Token: Hashable
extension Token: Identifiable

A class to represent a Token on the Tezos network. This class will do all the heavy lifting of converting values from the RPC to more human readbale values. This class will also handle arithmetic functions, allowing developers to add and subtract tokens (useful when caluclating fees and total values).

  • An Enum to express the type of a token. Different processes are needed to fetch a balance for a users XTZ wallet, versus fetching a FA1.2 token balance. This allows the library to abstract this logic away from the user and handle it all behind the scenes.

    See more

    Declaration

    Swift

    public enum TokenType : String, Codable
  • The long name of a token. e.g. “Tezos”.

    Declaration

    Swift

    public let name: String?
  • The short name or the symbol of a token. e.g. “XTZ”.

    Declaration

    Swift

    public let symbol: String
  • The type of this token. e.g. xtz, fungible, nonfungible

    Declaration

    Swift

    public let tokenType: TokenType
  • The FaVersion of the token contract, nil for XTZ

    Declaration

    Swift

    public let faVersion: FaVersion?
  • Object that holds and formats the balance of the token

    Declaration

    Swift

    public var balance: TokenAmount
  • Object that holds and formats the staked balance of the token

    Declaration

    Swift

    public var stakedBalance: TokenAmount
  • Object that holds and formats the pending unstaked balance of the token

    Declaration

    Swift

    public var unstakedBalance: TokenAmount
  • helper to return the available spendable balance of the token (balance - stakedBalance) - unstakedBalance

    Declaration

    Swift

    public var availableBalance: TokenAmount { get }
  • Get the underlying number of decimal places that this token represents

    Declaration

    Swift

    public var decimalPlaces: Int { get }
  • The URL to a cached version of the asset (data that we add later on through other service calls)

    Declaration

    Swift

    public var thumbnailURL: URL?
  • The current local currency rate of this token. Used to show the user the net worth of their holdings.

    Declaration

    Swift

    public var localCurrencyRate: Decimal
  • In the case of FA1.2 or higher, we need to know the KT1 address for the token so we can fetch balances and make trades. (should be empty for xtz).

    Declaration

    Swift

    public let tokenContractAddress: String?
  • Each token type on a contract will have a unique token_id

    Declaration

    Swift

    public var tokenId: Decimal?
  • Recording if the user has marked the token as hidden

    Declaration

    Swift

    public var isHidden: Bool
  • Recording if the position the index the user chose for the favourite token to appear

    Declaration

    Swift

    public var favouriteSortIndex: Int?
  • The block level where the token was first seen

    Declaration

    Swift

    public var firstlevel: Decimal
  • The block level where the token was last seen

    Declaration

    Swift

    public var lastLevel: Decimal
  • The individual NFT’s owned of this token type

    Declaration

    Swift

    public var nfts: [NFT]?
  • The URL of the tool used to mint the item

    Declaration

    Swift

    public var mintingTool: String?
  • Declaration

    Swift

    public var isFavourite: Bool { get }

Init

  • Init a Token object that will hold all the necessary data to interact with the Tezos network, and the Dexter exchange

    Declaration

    Swift

    public init(name: String?, symbol: String, tokenType: TokenType, faVersion: FaVersion?, balance: TokenAmount, stakedBalance: TokenAmount? = nil, unstakedBalance: TokenAmount? = nil, thumbnailURL: URL?, tokenContractAddress: String?, tokenId: Decimal?, nfts: [NFT]?, mintingTool: String?)

    Parameters

    name

    The long name of the token. e.g. “Tezos”

    symbol

    The short name of the token, or the symbol. e.g. “XTZ”

    tokenType

    The type of the token. e.g. xtz, fa1.2, fa2 etc.

    faVersion

    The FA standard / version used to create this token.

    decimalPlaces

    The number of decimal places this token contains.

    thumbnailURI

    URI to network asset to use to display an icon for the token

    tokenContractAddress

    The KT1 address of the contract (nil if xtz).

    tokenId

    The token id if the token is an FA2 token, nil otherwise.

    nfts

    The individual NFT’s owned of this token type

  • Init a Token from an object returned by the TzKT API

    Declaration

    Swift

    public init(from: TzKTBalance, andTokenAmount: TokenAmount, stakedTokenAmount: TokenAmount? = nil, unstakedTokenAmount: TokenAmount? = nil)
  • Init a Token from an object returned by the TzKT API

    Declaration

    Swift

    public init(from: TzKTTokenTransfer)
  • Create a Token object with all the settings needed for XTZ

    Declaration

    Swift

    public static func xtz() -> Token

    Return Value

    Token

  • Create a Token object with all the settings needed for XTZ, with an initial amount. Useful for setting fees.

    Declaration

    Swift

    public static func xtz(withAmount amount: TokenAmount, stakedAmount: TokenAmount = .zeroBalance(decimalPlaces: 6), unstakedAmount: TokenAmount = .zeroBalance(decimalPlaces: 6)) -> Token

    Parameters

    withAmount

    The Amount of XTZ to create the Token with.

    Return Value

    Token.

  • Useful for creating placeholders for pending activity items

    Declaration

    Swift

    public static func placeholder(fromNFT nft: NFT, amount: TokenAmount, thumbnailURL: URL?) -> Token
  • Conforming to CustomStringConvertible to print a number, giving the appearence of a numeric type

    Declaration

    Swift

    public var description: String { get }
  • Helper function to check if the Token instance being passed aroun is pointing to XTZ. As many functions will require different functionality for fa token versus XTZ

    Declaration

    Swift

    public func isXTZ() -> Bool
  • Conforming to Equatable to enable working with UITableViewDiffableDataSource

    Declaration

    Swift

    public static func == (lhs: Token, rhs: Token) -> Bool
  • Conforming to Hashable to enable working with UITableViewDiffableDataSource

    Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • id

    Conforming to Identifiable to enable working with ForEach and similiar looping functions if faVersion present, use that to follow the standard of either tokenAddress or combination of tokenAddress + token id, fallback to using symbol if type is unknown

    Declaration

    Swift

    public var id: String { get }