Represents a hexadecimal numeric value compatible with the result of ethers utils.toQuantity function. This is most commonly used for JSON-RPC numeric values.

A quantity instance:

  • has not empty content,
  • the hexadecimal representation removes any not meaningful zero on the left side of the expression,
  • represents only positive integers.

Hierarchy (view full)

Constructors

  • Creates a new instance of this class to represent the value built multiplying sign for the absolute value expressed by the hexadecimal digits.

    Parameters

    • sign: number

      The sign of the value.

    • digits: string

      The digits of the absolute value in hexadecimal base.

    • Optionalnormalize: ((digits: string) => string) = ...

      The function used to normalize the digits. Defaults to converting digits to lowercase.

        • (digits): string
        • Parameters

          • digits: string

          Returns string

    Returns Quantity

Properties

digits: string

Returns the hexadecimal digits expressing this absolute value, sign and 0x prefix omitted.

An empty content results in an empty string returned.

sign: number

Represents the sign multiplier of a given number:

NEGATIVE: number = -1

Negative multiplier of the digits absolute value.

POSITIVE: number = 1

Positive multiplier of the digits absolute value.

PREFIX: "0x" = '0x'

A constant string prefix used in hexadecimal notation.

RADIX: number = 16

The radix used for representing numbers base 16 in a positional numeral notation system.

REGEX_HEX_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

REGEX_HEXUINT_PREFIX: RegExp = ...

Regular expression pattern to match a prefix indicating hexadecimal number.

Accessors

  • get abs(): Hex
  • Returns the absolute value of this Hex object.

    Returns Hex

    A new Hex object representing the absolute value of this Hex.

  • get bi(): bigint
  • Returns the value of bi as a BigInt type.

    Returns bigint

    The value of bi as a BigInt.

  • get bytes(): Uint8Array
  • Returns the Uint8Array representation of the aligned bytes.

    Returns Uint8Array

    The Uint8Array representation of the aligned bytes.

  • get n(): number
  • Retrieves the value of n cast from this instance interpreted as the hexadecimal expression of a bigint value.

    Returns number

    The value of n.

    If n is not within the safe number range, if the number representation of this instance results approximated.

    This class makes equal instances created from the same value as number or as bigint.

Methods

  • Compares the current Hex object with another Hex object.

    Parameters

    • that: Hex

      The Hex object to compare with.

    Returns number

    • Returns a negative number if the current Hex object is less than the given Hex object, zero if they are equal, or a positive number if the current Hex object is greater than the given Hex object.
  • Returns a new instance of the Hex class, its value fits to the specified number of digits.

    Parameters

    • digits: number

      The number of digits to fit the Hex value into.

    Returns Hex

    • A new Hex instance that represents the fitted Hex value.
    • If the Hex value cannot be fit into the specified number of digits.
  • Determines whether this Hex instance is equal to the given Hex instance.

    Parameters

    • that: Hex

      The Hex instance to compare with.

    Returns boolean

    • True if the Hex instances are equal, otherwise false.
  • Returns a string representation of the object.

    Parameters

    • compact: boolean = false

      Whether to compact the string representation.

    Returns string

    The string representation of the object.

  • Checks if the given string expression is a valid unsigned hexadecimal value.

    Parameters

    • exp: string

      The string representation of a hexadecimal value.

    Returns boolean

    • True if the expression is a valid unsigned hexadecimal value, case-insensitive, optionally prefixed with 0x; false otherwise.
  • Determines whether the given string is a valid unsigned hexadecimal number prefixed with '0x'.

    Parameters

    • exp: string

      The string to be evaluated.

    Returns boolean

    • True if the string is a valid unsigned hexadecimal number prefixed with '0x', otherwise false.
  • Creates a Quantity instance from a bigint or number given expression

    Parameters

    • exp: number | bigint

      The value to be expressed as Quantity object:

      • bigint must be positive;
      • number must be positive, it is converted to bigint to create the Quantity.

    Returns Quantity

    • The new Quantity object.
    • If the provided expression is not a positive integer value.
  • Generates a random Hex value of the given number of bytes length.

    Parameters

    • bytes: number

      The number of bytes to generate.

    Returns Hex

    • A randomly generated Hex value.
    • If the bytes argument is not greater than 0.

    Security auditable method, depends on