# Symbol
A symbol store code and precision of the token amount.
It is important to note that smart contracts view token amounts as raw values without decimals. Take for example XPR with precision 4. A symbol representing 1.2345 XPR would have an amount value of 12345.
# Constructors
constructor( name: string="", precision: u8=0 )name- The symbol code of the token.Example: XPRprecision- The number that indicates the precision for current amountExample: 4Example:
import { Symbol } from 'proton-tsc' const symbol = new Symbol("XPR", 4)
static fromU64(value: u64): SymbolCreates new symbol from u64 number
Example:
const symbol = Symbol.fromU64(1380997124) // XPR,4
# Instance Methods
fromU64(value: u64): SymbolCreates new symbol from u64 number.
Example:
const symbol = new Symbol("XUSDC", 6); const new_symbold = symbol.fromU64(1380997124); print(symbol.toString()); // 4,XPRgetSymbolString(): stringReturns the symbol code
Example:
const symbol = new Symbol("XUSDC", 6); print(symbol.getSymbolString()); // XUSDCcode(): u64Returns the code of the symbol as u64 number
Example:
const symbol = new Symbol("XUSDC", 6); printui(symbol.code()); // 288909120856,precision(): u8Returns the precision of the symbol
Example:
const symbol = new Symbol("XUSDC", 6); printui(symbol.precision()); // 6,isValid(): boolChecks the symbol is valid
toString(): stringReturns the symbol as a string in format
precision,symbolExample:
const symbol = new Symbol("XUSDC", 6); print(symbol.toString()); // 6,XUSDC
# Static Methods
static function eq(a: Symbol, b: Symbol): boolChecks that two symbols are equal
Throws if:
- Symbols do not match
static function neq(a: Symbol, b: Symbol): boolChecks that two symbols are not equal
Throws if:
- Symbols are equal
static function lt(a: Symbol, b: Symbol): boolChecks that the symbol a is less than b
Throws if:
- Symbols a is greater or equal b
← Name ExtendedSymbol →