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 VarInt

Properties

value: BN

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

abiName: string
byteWidth: number
isSigned: boolean

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

  • Parameters

    • type: string

    Returns string | number

  • Mutating add.

    Parameters

    • num: any

    Returns void

  • Non-mutating add.

    Parameters

    • num: any

    Returns VarInt

  • 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.

    Throws

    When dividing by zero.

    Parameters

    • by: any
    • Optional behavior: DivisionBehavior

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

    Returns void

  • Non-mutating divide.

    Throws

    When dividing by zero.

    Parameters

    • by: any
    • Optional behavior: DivisionBehavior

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

    Returns VarInt

  • 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: any
    • Optional strict: boolean

    Returns boolean

  • Mutating multiply.

    Parameters

    • by: any

    Returns void

  • Non-mutating multiply.

    Parameters

    • by: any

    Returns VarInt

  • Mutating subtract.

    Parameters

    • num: any

    Returns void

  • Non-mutating subtract.

    Parameters

    • num: any

    Returns VarInt

  • Called when encoding to binary abi format.

    Parameters

    Returns void

  • Called when encoding to json abi format.

    Returns string | number

  • Convert to a JavaScript number.

    Throws

    If the number cannot be represented by 53-bits.

    Returns number

  • Returns string

  • Returns Int

  • Divide lhs by rhs and return the quotient, dropping the remainder.

    Throws

    When dividing by zero.

    Parameters

    Returns Int

  • Divide lhs by rhs and return the quotient + remainder rounded up to the closest integer.

    Throws

    When dividing by zero.

    Parameters

    Returns Int

  • Divide lhs by rhs and return the quotient + remainder rounded to the closest integer.

    Throws

    When dividing by zero.

    Parameters

    Returns Int

  • Create a new instance from value.

    Type Parameters

    • T extends typeof Int

    Parameters

    • this: T
    • value: any

      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

  • Type Parameters

    • T extends typeof Int

    Parameters

    • this: T

    Returns InstanceType<T>

  • Returns unknown