NOTE: Do not use this class when working with account addresses, use AccountAddress.

NOTE: When accepting hex data as input to a function, prefer to accept HexInput and then use the static helper methods of this class to convert it into the desired format. This enables the greatest flexibility for the developer.

Hex is a helper class for working with hex data. Hex data, when represented as a string, generally looks like this, for example: 0xaabbcc, 45cd32, etc.

You might use this class like this:

getTransactionByHash(txnHash: HexInput): Promise<Transaction> {
const txnHashString = Hex.fromHexInput(txnHash).toString();
return await getTransactionByHashInner(txnHashString);
}

This call to Hex.fromHexInput().toString() converts the HexInput to a hex string with a leading 0x prefix, regardless of what the input format was.

These are some other ways to chain the functions together:

  • Hex.fromHexString({ hexInput: "0x1f" }).toUint8Array()
  • new Hex([1, 3]).toStringWithoutPrefix()

Constructors

  • Create a new Hex instance from a Uint8Array.

    Parameters

    • data: Uint8Array

      Uint8Array

    Returns Hex

Properties

data: Uint8Array

Methods

  • Return whether Hex instances are equal. Hex instances are considered equal if their underlying byte data is identical.

    Parameters

    • other: Hex

      The Hex instance to compare to.

    Returns boolean

    true if the Hex instances are equal, false if not.

  • Get the hex data as a string with the 0x prefix.

    Returns string

    Hex string with 0x prefix

  • Get the hex data as a string without the 0x prefix.

    Returns string

    Hex string without 0x prefix

  • Get the inner hex data. The inner data is already a Uint8Array so no conversion is taking place here, it just returns the inner data.

    Returns Uint8Array

    Hex data as Uint8Array

  • Static method to convert an instance of HexInput to Hex

    Parameters

    • hexInput: HexInput

      A HexInput (string or Uint8Array)

    Returns Hex

    Hex

  • Static method to convert a hex string to Hex

    Parameters

    • str: string

      A hex string, with or without the 0x prefix

    Returns Hex

    Hex

Generated using TypeDoc