5.7.1 Java  Script Types loader.mjs Account Handles Contract Handles Network Utilities Provider Selection 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
number  To  Fixed  Point
parse  Int
number  To  Int
standard  Unit
atomic  Unit
minimum  Balance
parse  Currency
format  Currency
format  Address 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(ty:Type, x:ty) => Digest

Hashes the value.

randomUInt() => UInt

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


hasRandom (Frontend) A value suitable for use as a participant interact interface requiring a random function, such as hasRandom. Reach does not natively support randomness and leaves random number generation to the frontend implementation. This value is provided out of convenience; it is not mandatory to use this implementation.


hasConsoleLogger (Frontend) A value suitable for use as a participant interact interface requiring a log function, such as hasConsoleLogger. The log function provided takes an arbitrary amount of elements and prints them to stdout. This value is provided out of convenience; it is not mandatory to use this implementation.

parseFixedPoint(FixedPoint) => number

Parses a FixedPoint number into a JavaScript number.

numberToFixedPoint(number) => FixedPoint

Parses a JavaScript number into a FixedPoint.

parseInt(Int) => number

Parses a signed Int into a JavaScript number.

numberToInt(number) => Int

Parses a JavaScript number into an Int.

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.

formatAddress(acc) => string

Formats the address in the way the user would expect to see it.

There is no corresponding parseAddress function because the user-friendly form is also accepted from the frontend in all places that Reach expects an address.