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

Constructors

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

    Throws

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

    Parameters

    • value: BN

    Returns VarUInt

Properties

value: BN

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

abiName: string = 'varuint32'
byteWidth: number = 32
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>

  • 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

  • Convert to a JavaScript number.

    Throws

    If the number cannot be represented by 53-bits.

    Returns number

  • 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

Generated using TypeDoc