Global

Members

Block

Retrieve head block inforamtions.

Example
import { Block } from "ultrain-ts-lib/src/block";

Contract

It is the base class of any executable contract, each concrete contract should extend class Contract.

Example
import { Contract } from "ultrain-ts-lib/src/contract";

Log

A global variable of Logger. There is only one Log object at the same time. This is a global instance of {@class Logger}.

Example
import { Log } from "ultrain-ts-lib/src/log";

Logger

class Logger providers api to print logs to console immediately after you call function 'flush'.

SafeMath

Math operations with safety checks that throw on error

Example
import { SafeMath } from "ultrain-ts-lib/src/safemath";

Methods

emit(evtname, obj)

to emit an event.

Example
import { emit } from "ultrain-ts-lib/src/events";
Parameters:
Name Type Description
evtname

the name of event to be emitted, its length MUST be less than 64 characters.

obj

EventObject contains message. The contents's serialized length must be less than your configed contract_event_string_length, the default serialized contents length is 128.

Returns:

i32 value. 0: successed; -1: event name is too long; -2: event message is too long.

intToString(_int, leftPadWith0)

convert an uint64 to string.

Example
import { intToString } from "ultrain-ts-lib/src/utils";
Parameters:
Name Type Description
_int

uint64 to convert

leftPadWith0

width of integer, if length of integer is less than it, pad with 0 on left.

Returns:

string

now()

This function return the head block time, it is in seconds since epoch.

Example
import { now } from "ultrain-ts-lib/src/time";

Return(val)

set value as return value. This value will be printed to console or return within response if you call API by POST method via https. Till now, type T can only be string or integer. NOTE: the return value doesn't mean the transaction is commited by blockchain, but means if the transaction is executed, the result will be it.

Example
import { Return } from "ultrain-ts-lib/src/return";
Parameters:
Name Type Description
val

value will set as return value.

ReturnArray(val)

return an array to caller. It behaves like Return.

Example
import { ReturnArray } from "ultrain-ts-lib/src/return";
Parameters:
Name Type Description
val

an array of returns value.

string2cstr(str)

convert string to usize. here, usize likes "const char*" in c/c++.

Example
import { string2cstr } from "ultrain-ts-lib/src/utils";
Parameters:
Name Type Description
str

a utf-16 string of typescript.

Returns:

usize

toUTF8Array(str)

convert an utf-16 to utf-8 string array.

Example
import { toUTF8Array } from "ultrain-ts-lib/src/utils";
Parameters:
Name Type Description
str

a typescript string

Returns:

an array of uint8