Function createHex

  • Create a hexadecimal string from a bytes-like value.

    • If the value is a hex string (i.e., it starts with "0x"), it is returned as-is.
    • If the value is a Uint8Array, it is converted to a hex string.

    Example

    const value = createHex(new Uint8Array([1, 2, 3]));
    console.log(value); // '0x010203'

    const otherValue = createHex('0x010203');
    console.log(otherValue); // '0x010203'

    Returns

    The created hex string.

    Throws

    If the value is not a bytes-like value.

    Parameters

    • value: Uint8Array | `0x${string}`

      The value to create the hex string from.

    Returns Hex