eos-common
EOSIO Smart Contract common library used for Typescript
Goal
To implement the 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 = new Asset(10000, new Symbol("EOS", 4));
quantity.toString()
quantity.symbol.code()
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
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
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
SymbolCode
Symbol
Symbol
Parameters
Examples
const sym = new Symbol("EOS", 4);
sym.code()
sym.precision
Returns Symbol Symbol
stake2vote
Convert EOS stake into decaying value
Parameters
vote2stake
Convert vote decay value into EOS stake
Parameters
voteWeightToday
voteWeightToday computes the stake2vote weight for EOS, in order to compute the decaying value.
split
Split quantity string
Parameters
quantity
string Quantity string
Examples
const quantity = split("1.0000 EOS");
quantity.amount
quantity.symbol.precision
quantity.symbol.code()
Returns Asset