5.7.1 Java  Script Types loader.mjs Accounts Contracts Network Utilities Utilities ask.mjs
On this page:
T_  Null
T_  Bool
T_  UInt
T_  Bytes
T_  Address
T_  Array
T_  Tuple
T_  Object
Array_  set
big  Numberify
is  Big  Number
is  Hex
hex  To  Big  Number
string  To  Hex
big  Number  To  Hex
uint  To  Bytes
bytes  Eq
digest  Eq
address  Eq
random  UInt
parse  Fixed  Point
parse  Int
standard  Unit
atomic  Unit
minimum  Balance
parse  Currency
format  Currency Utilities

These functions operate on JavaScript representations of Reach values.

protect(t, x) => x 

Asserts that value x has Reach type t. An exception is thrown if this is not the case.

T_Null => ReachType
T_Bool => ReachType
T_UInt => ReachType
T_Bytes(number) => ReachType
T_Digest => ReachType
T_Address => ReachType
T_Array(ReachType, number) => ReachType
T_Tuple([ReachType ...]) => ReachType
T_Object({Key: ReachType ...}) => ReachType
T_Data({Variant: ReachType ...}) => ReachType

Each of these represent the corresponding Reach type.


Throws an exception if not given true.

Array_set(arr, idx, val) 

Returns a new array identical to arr, except that index idx is val.

bigNumberify(x) => UInt
isBigNumber(x) => bool
bigNumberToNumber(x) => number

bigNumberify converts a JavaScript number to a BigNumber, the JavaScript representation of Reach’s UInt.

isBigNumber checks if its input is a BigNumber.

bigNumberToNumber transparently applies bigNumberify to its argument and returns a JavaScript number.

isHex(x) => bool
hexToBigNumber(bytes) => UInt
stringToHex(string) => bytes
bigNumberToHex(UInt) => bytes
uintToBytes(UInt) => bytes
bytesEq(bytes, bytes) => bool
digestEq(Digest, Digest) => bool
addressEq(Address, Address) => bool

These are additional conversion and comparison utilities.

digest(x) => Digest

Hashes the value.

randomUInt() => UInt

Generates random bits as a UInt. The number of bits generated depends on the particular consensus network.


A value suitable for use as a participant interact interface requiring a random function.

parseFixedPoint(FixedPoint) => number

Parses a FixedPoint number into a Javascript number.

parseInt(Int) => number

Parses a signed Int into a Javascript number.

add(UInt, UInt) => UInt
sub(UInt, UInt) => UInt
mod(UInt, UInt) => UInt
mul(UInt, UInt) => UInt
div(UInt, UInt) => UInt 

Integer arithmetic on UInt.

eq(UInt, UInt) => bool
ge(UInt, UInt) => bool
gt(UInt, UInt) => bool
le(UInt, UInt) => bool
lt(UInt, UInt) => bool

Integer comparisons on UInt.

The following exports are for dealing with network tokens.

standardUnit // string
atomicUnit // string
minimumBalance // atomicUnitAmount
parseCurrency(standardUnitAmount) => atomicUnitAmount
formatCurrency(atomicUnitAmount, int) => string  // display amount in standard unit

These functions handle amounts in a network’s standard unit and its atomic unit. A standard unit is the network token unit most commonly associated with a network. For example, the standard unit of Ethereum is ETH. An atomic unit is the smallest unit of measure for the standard unit. For example, the atomic unit of Ethereum is WEI. An atomic unit is atomic, which means it cannot be divided into smaller units.

Some consensus networks, typically those with proof-of-stake, have minimum balances on their accounts, so this is exposed as minimumBalance.

Because there are 1,000,000,000,000,000,000 WEI in 1 ETH, BigNumber is used to represet values in WEI.

Quantities of a network token should always be passed into Reach in the token’s atomic unit.

bigNumberify is transparently applied to formatCurrency’s first argument.