Function createBytes

  • Create a byte array from a bytes-like value.

    • If the value is a byte array, it is returned as-is.
    • If the value is a hex string (i.e., it starts with "0x"), it is interpreted as a hexadecimal number and converted to a byte array.

    Example

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

    const otherValue = createBytes('0x010203');
    console.log(otherValue); // Uint8Array [ 1, 2, 3 ]

    Returns

    The created byte array.

    Throws

    If the value is not a bytes-like value.

    Parameters

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

      The value to create the byte array from.

    Returns Uint8Array