Binary integer with the underlying value represented by a BN.js instance. Follows C++11 standard for arithmetic operators and conversions.

Note

This type is optimized for correctness not speed, if you plan to manipulate integers in a tight loop you're advised to use the underlying BN.js value or convert to a JavaScript number first.

Hierarchy-Diagram

UML class diagram of UInt128
Legend
icon for a class in the UML class diagram class
icon for a public method in the UML class diagram public method
underlined static property/method

Hierarchy (view full)

Constructors

  • Create a new instance, don't use this directly. Use the .from factory method instead.

    Parameters

    • value: BN

    Returns UInt128

    Throws

    If the value over- or under-flows the integer type.

Properties

value: BN

The underlying BN.js instance – don't modify this directly – take a copy first using .clone().

abiName: string = 'uint128'
byteWidth: number = 16
isSigned: boolean = false

Accessors

  • get byteArray(): Uint8Array
  • Number as bytes in little endian (matches memory layout in C++ contract).

    Returns Uint8Array

  • get max(): BN
  • Largest value that can be represented by this integer type.

    Returns BN

  • get min(): BN
  • Smallest value that can be represented by this integer type.

    Returns BN

Methods

  • Cast this integer to other type.

    Type Parameters

    • T extends typeof Int

    Parameters

    • type: T
    • Optional overflow: OverflowBehavior

      How to handle overflow, default is to preserve bit-pattern (C++11 behavior).

    Returns InstanceType<T>

  • Mutating divide.

    Parameters

    • by: IntType
    • Optional behavior: DivisionBehavior

      How to handle the remainder, default is to floor (round down).

    Returns void

    Throws

    When dividing by zero.

  • Compare two integers, if strict is set to true the test will only consider integers of the exact same type. I.e. Int64.from(1).equals(UInt64.from(1)) will return false.

    Parameters

    • other: Uint8Array | IntType
    • strict: boolean = false

    Returns boolean

  • Greater than or equal comparision operator

    Parameters

    Returns boolean

  • Less than or equal comparision operator

    Parameters

    Returns boolean

  • Called when encoding to json abi format.

    Returns string | number

  • Convert to a JavaScript number.

    Returns number

    Throws

    If the number cannot be represented by 53-bits.

  • Create a new instance from value.

    Type Parameters

    • T extends typeof Int

    Parameters

    • this: T
    • value: Uint8Array | IntType

      Value to create new Int instance from, can be a string, number, little-endian byte array or another Int instance.

    • Optional overflow: OverflowBehavior

      How to handle integer overflow, default behavior is to throw.

    Returns InstanceType<T>

  • Parameters

    Returns unknown

  • Compare lhs to rhs and return true if lhs is greater than rhs.

    Parameters

    Returns boolean

  • Compare lhs to rhs and return true if lhs is greater than or equal to rhs.

    Parameters

    Returns boolean

  • Compare lhs to rhs and return true if lhs is less than rhs.

    Parameters

    Returns boolean

  • Compare lhs to rhs and return true if lhs is less than or equal to rhs.

    Parameters

    Returns boolean