eos-common
EOSIO Smart Contract common library used for Typescript
Implements most commonly used EOSIO C++ Classes into Typescript:
Installation
Using Yarn:
yarn add eos-common
or using NPM:
npm install --save eos-common
Quick Start
import { asset, symbol } from "eos-common"
const quantity = asset("1.0000 EOS");
const quantity = asset(10000, symbol("EOS", 4));
quantity.to_string()
quantity.symbol.code().to_string()
quantity.symbol.precision()
API
Table of Contents
Asset
Asset
Parameters
amount
number The amount of the assetsym
Symbol The name of the symbol
Examples
const quantity = new Asset(10000, new Symbol("EOS", 4));
quantity.toString()
quantity.symbol.code()
quantity.symbol.precision
Returns Asset Asset
amount
{int64_t} The amount of the asset
symbol
{symbol} The symbol name of the asset
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
is_amount_within_range
Check if the amount doesn't exceed the max amount
Returns any true - if the amount doesn't exceed the max amount
Returns any false - otherwise
is_valid
Check if the asset is valid. %A valid asset has its amount <= max_amount and its symbol name valid
Returns any true - if the asset is valid
Returns any false - otherwise
set_amount
Set the amount of the asset
Parameters
amount
a
New amount for the asset
minus
Subtraction assignment operator
Parameters
a
Another asset to subtract this asset with
Returns any asset& - Reference to this asset
plus
Addition Assignment operator
Parameters
a
Another asset to subtract this asset with
Returns any asset& - Reference to this asset
times
Multiplication assignment operator, with a number
Parameters
a
The multiplier for the asset's amount
Returns any asset - Reference to this asset
div
Parameters
a
The divisor for the asset's amount
Returns any asset - Reference to this asset
toString
The toString() method returns the string representation of the object.
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
plus
Addition operator
Parameters
a
The first asset to be addedb
The second asset to be added
Returns any asset - New asset as the result of addition
minus
Subtraction operator
Parameters
a
The asset to be subtractedb
The asset used to subtract
Returns any asset - New asset as the result of subtraction of a with b
times
Multiplication operator, with a number proceeding
Parameters
a
The asset to be multipliedb
The multiplier for the asset's amount
Returns any asset - New asset as the result of multiplication
div
Division operator, with a number proceeding
Parameters
a
The asset to be dividedb
The divisor for the asset's amount
Returns any asset - New asset as the result of division
isEqual
Equality operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if both asset has the same amount
Returns any false - otherwise
isNotEqual
Inequality operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if both asset doesn't have the same amount
Returns any false - otherwise
isLessThan
Less than operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if the first asset's amount is less than the second asset amount
Returns any false - otherwise
isLessThanOrEqual
Less or equal to operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if the first asset's amount is less or equal to the second asset amount
Returns any false - otherwise
isGreaterThan
Greater than operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if the first asset's amount is greater than the second asset amount
Returns any false - otherwise
isGreaterThanOrEqual
Greater or equal to operator
Parameters
a
The first asset to be comparedb
The second asset to be compared
Returns any true - if the first asset's amount is greater or equal to the second asset amount
Returns any false - otherwise
max_amount
{constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1
check
Assert if the predicate fails and use the supplied message.
Parameters
Examples
check(a == b, "a does not equal b");
Returns void
write_decimal
Writes a number as a string
Parameters
number
The number to print before shifting the decimal point to the left by num_decimal_places.num_decimal_places
The number of decimal places to shift the decimal point.negative
Whether to print a minus sign in the front.
ExtendedAsset
Parameters
quantity
The asset
contract
The owner of the asset
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
get_extended_symbol
Get the extended symbol of the asset
Returns any extended_symbol - The extended symbol of the asset
toString
The toString() method returns the string representation of the object.
times
Multiplication assignment operator
Parameters
div
Division operator
Parameters
minus
Subtraction operator
Parameters
plus
Addition operator
Parameters
isLessThan
Less than operator
Parameters
isEqual
Comparison operator
Parameters
isNotEqual
Comparison operator
Parameters
isLessThanOrEqual
Comparison operator
Parameters
isGreaterThanOrEqual
Comparison operator
Parameters
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
ExtendedSymbol
Parameters
sym
The symbolcontract
con
The name of the contract
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
get_symbol
Returns the symbol in the extended_contract
Returns any symbol
get_contract
Returns the name of the contract in the extended_symbol
Returns any name
toString
The toString() method returns the string representation of the object.
Parameters
show_precision
(optional, default true
)
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
isEqual
Equivalency operator. Returns true if a == b (are the same)
Parameters
Returns any boolean - true if both provided name are the same
isNotEqual
Inverted equivalency operator. Returns true if a != b (are different)
Parameters
Returns any boolean - true if both provided name are not the same
isLessThan
Less than operator. Returns true if a < b.
Parameters
Returns any boolean - true if name a
is less than b
extended_symbol
Extended Symbol
Parameters
Examples
extended_symbol( symbol("4,EOS"), name("eosio.token") )
Name
Parameters
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
length
Returns the length of the %name
suffix
Returns the suffix of the %name
raw
Returns uint64_t repreresentation of the name
bool
Explicit cast to bool of the name
Returns any Returns true if the name is set to the default value of 0 else true.
toString
The toString() method returns the string representation of the object.
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
char_to_value
Converts a %name Base32 symbol into its corresponding value
Parameters
c
Character to be converted
Returns any constexpr char - Converted value
isEqual
Equivalency operator. Returns true if a == b (are the same)
Parameters
Returns any boolean - true if both provided name are the same
isNotEqual
Inverted equivalency operator. Returns true if a != b (are different)
Parameters
Returns any boolean - true if both provided name are not the same
isLessThan
Less than operator. Returns true if a < b.
Parameters
Returns any boolean - true if name a
is less than b
SymbolCode
Parameters
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
toString
The toString() method returns the string representation of the object.
isEqual
Equivalency operator. Returns true if a == b (are the same)
Parameters
Returns any boolean - true if both provided symbol_codes are the same
isNotEqual
Inverted equivalency operator. Returns true if a != b (are different)
Parameters
Returns any boolean - true if both provided symbol_codes are not the same
isLessThan
Less than operator. Returns true if a < b.
Parameters
Returns any boolean - true if symbol_code a
is less than b
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
Symbol
Symbol
Parameters
Examples
const sym = new Symbol("EOS", 4);
sym.code()
sym.precision
Returns Symbol Symbol
typeof
The typeof operator returns a string indicating the type of the unevaluated operand.
is_valid
Is this symbol valid
precision
This symbol's precision
code
Returns representation of symbol name
raw
Returns uint64_t repreresentation of the symbol
bool
Explicit cast to bool of the symbol
Returns any Returns true if the symbol is set to the default value of 0 else true.
toString
The toString() method returns the string representation of the object.
Parameters
show_precision
(optional, default true
)
isInstance
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
Parameters
isEqual
Equivalency operator. Returns true if a == b (are the same)
Parameters
Returns any boolean - true if both provided symbol_codes are the same
isNotEqual
Inverted equivalency operator. Returns true if a != b (are different)
Parameters
Returns any boolean - true if both provided symbol_codes are not the same
isLessThan
Less than operator. Returns true if a < b.
Parameters
Returns any boolean - true if symbol_code a
is less than b
voteWeightToday
voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value.
stake2vote
Convert EOS stake into decaying value
Parameters
vote2stake
Convert vote decay value into EOS stake
Parameters
calculate_producer_per_vote_pay
Calculate producer vpay
Parameters
total_votes
pervote_bucket
total_producer_vote_weight
Returns bigint producer pay as int64t