Hex class

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

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

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.

Example usage:

Future<Transaction> getTransactionByHash(HexInput txnHash) {
  final txnHashString = Hex.fromHexInput(txnHash).toString();
  return getTransactionByHashInner(txnHashString);
}

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

Constructors

Hex(Uint8List data)
Create a new Hex instance from a Uint8List.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

equals(Hex other) → bool
Determine if two Hex instances are equal by comparing their underlying byte data.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
Get the hex data as a string with the 0x prefix.
override
toStringWithoutPrefix() → String
Get the hex data as a string without the 0x prefix.
toUint8List() → Uint8List
Get the inner hex data as a Uint8List. The inner data is already a Uint8List, so no conversion takes place.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromHexInput(HexInput hexInput) → Hex
Converts an instance of HexInput, which can be a String or a Uint8List, into a Hex instance.
fromHexString(String str) → Hex
Converts a hex string into a Hex instance, allowing for both prefixed and non-prefixed formats.
hexInputToString(HexInput hexInput) → String
Converts a HexInput (string or bytes) to a hex string with '0x' prefix.
hexInputToStringWithoutPrefix(HexInput hexInput) → String
Converts a HexInput (string or bytes) to a hex string without the '0x' prefix.
hexInputToUint8List(HexInput hexInput) → Uint8List
Converts an instance of HexInput, which can be a String or a Uint8List, into a Uint8List.
isValid(String str) → ParsingResult<HexInvalidReason>
Check if the provided string is a valid hexadecimal representation.