EOSIO Smart Contract common library used for Typescript
Implements most commonly used EOSIO C++ Classes into Typescript:
Using Yarn:
yarn add eos-common
or using NPM:
npm install --save eos-common
import { asset, symbol } from "eos-common"
const quantity = asset("1.0000 EOS");
// or
const quantity = asset(10000, symbol("EOS", 4));
quantity.to_string() //=> "1.0000 EOS";
quantity.symbol.code().to_string() //=> "EOS"
quantity.symbol.precision() //=> 4
- Asset
- check
- write_decimal
- ExtendedAsset
- extended_asset
- ExtendedSymbol
- extended_symbol
- Name
- SymbolCode
- Symbol
- typeof
- is_valid
- precision
- code
- raw
- bool
- toString
- isInstance
- isEqual
- isNotEqual
- isLessThan
- voteWeightToday
- stake2vote
- vote2stake
- calculate_producer_per_vote_pay
Asset
const quantity = new Asset(10000, new Symbol("EOS", 4));
quantity.toString() //=> "1.0000 EOS";
quantity.symbol.code() //=> "EOS"
quantity.symbol.precision //=> 4
Returns Asset Asset
{int64_t} The amount of the asset
{symbol} The symbol name of the asset
The typeof operator returns a string indicating the type of the unevaluated operand.
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
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 the amount of the asset
amount
a
New amount for the asset
Subtraction assignment operator
a
Another asset to subtract this asset with
Returns any asset& - Reference to this asset
Addition Assignment operator
a
Another asset to subtract this asset with
Returns any asset& - Reference to this asset
Multiplication assignment operator, with a number
a
The multiplier for the asset's amount
Returns any asset - Reference to this asset
a
The divisor for the asset's amount
Returns any asset - Reference to this asset
The toString() method returns the string representation of the object.
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Addition operator
a
The first asset to be addedb
The second asset to be added
Returns any asset - New asset as the result of addition
Subtraction operator
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
Multiplication operator, with a number proceeding
a
The asset to be multipliedb
The multiplier for the asset's amount
Returns any asset - New asset as the result of multiplication
Division operator, with a number proceeding
a
The asset to be dividedb
The divisor for the asset's amount
Returns any asset - New asset as the result of division
Equality operator
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
Inequality operator
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
Less than operator
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
Less or equal to operator
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
Greater than operator
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
Greater or equal to operator
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
{constexpr int64_t} Maximum amount possible for this asset. It's capped to 2^62 - 1
Assert if the predicate fails and use the supplied message.
check(a == b, "a does not equal b");
Returns void
Writes a number as a string
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.
obj1
obj2
The asset
The owner of the asset
The typeof operator returns a string indicating the type of the unevaluated operand.
Get the extended symbol of the asset
Returns any extended_symbol - The extended symbol of the asset
The toString() method returns the string representation of the object.
The toJSON() method returns the JSON representation of the object.
Multiplication assignment operator
a
Division operator
a
Subtraction operator
a
Addition operator
a
Less than operator
a
Comparison operator
a
Comparison operator
a
Comparison operator
a
Comparison operator
a
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Extended Asset
obj1
obj2
extended_asset( asset("1.0000 EOS"), name("eosio.token"))
obj1
obj2
The typeof operator returns a string indicating the type of the unevaluated operand.
Returns the symbol in the extended_contract
Returns any symbol
Returns the name of the contract in the extended_symbol
Returns any name
The toString() method returns the string representation of the object.
show_precision
(optional, defaulttrue
)
The toJSON() method returns the JSON representation of the object.
show_precision
(optional, defaulttrue
)
Returns uint128_t repreresentation of the extended symbol
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Equivalency operator. Returns true if a == b (are the same)
a
b
Returns any boolean - true if both provided name are the same
Inverted equivalency operator. Returns true if a != b (are different)
a
b
Returns any boolean - true if both provided name are not the same
Less than operator. Returns true if a < b.
a
b
Returns any boolean - true if name a
is less than b
Extended Symbol
obj1
obj2
extended_symbol( symbol("4,EOS"), name("eosio.token") )
str
The typeof operator returns a string indicating the type of the unevaluated operand.
Returns the length of the %name
Returns the suffix of the %name
Returns uint64_t repreresentation of the name
Explicit cast to bool of the name
Returns any Returns true if the name is set to the default value of 0 else true.
The toString() method returns the string representation of the object.
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Converts a %name Base32 symbol into its corresponding value
c
Character to be converted
Returns any constexpr char - Converted value
Equivalency operator. Returns true if a == b (are the same)
a
b
Returns any boolean - true if both provided name are the same
Inverted equivalency operator. Returns true if a != b (are different)
a
b
Returns any boolean - true if both provided name are not the same
Less than operator. Returns true if a < b.
a
b
Returns any boolean - true if name a
is less than b
obj
The typeof operator returns a string indicating the type of the unevaluated operand.
The toString() method returns the string representation of the object.
Equivalency operator. Returns true if a == b (are the same)
comparison
Returns any boolean - true if both provided symbol_codes are the same
Inverted equivalency operator. Returns true if a != b (are different)
comparison
Returns any boolean - true if both provided symbol_codes are not the same
Less than operator. Returns true if a < b.
comparison
Returns any boolean - true if symbol_code a
is less than b
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Symbol
const sym = new Symbol("EOS", 4);
sym.code() //=> "EOS"
sym.precision //=> 4
Returns Symbol Symbol
The typeof operator returns a string indicating the type of the unevaluated operand.
Is this symbol valid
This symbol's precision
Returns representation of symbol name
Returns uint64_t repreresentation of the symbol
Explicit cast to bool of the symbol
Returns any Returns true if the symbol is set to the default value of 0 else true.
The toString() method returns the string representation of the object.
show_precision
(optional, defaulttrue
)
The isinstance() function returns True if the specified object is of the specified type, otherwise False.
obj
Equivalency operator. Returns true if a == b (are the same)
a
b
Returns any boolean - true if both provided symbol_codes are the same
Inverted equivalency operator. Returns true if a != b (are different)
a
b
Returns any boolean - true if both provided symbol_codes are not the same
Less than operator. Returns true if a < b.
a
b
Returns any boolean - true if symbol_code a
is less than b
voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value.
Convert EOS stake into decaying value
staked
vote
number vote
Convert vote decay value into EOS stake
vote
staked
number staked
Calculate producer vpay
total_votes
pervote_bucket
total_producer_vote_weight
Returns bigint producer pay as int64t