Convert a byte-like value to a Uint8Array. The value can be a Uint8Array,
a bigint, a number, or a string.
This will attempt to guess the type of the value based on its type and
contents. For more control over the conversion, use the more specific
conversion functions, such as hexToBytes or stringToBytes.
If the value is a string, and it is prefixed with 0x, it will be
interpreted as a hexadecimal string. Otherwise, it will be interpreted as a
UTF-8 string. To convert a hexadecimal string to bytes without interpreting
it as a UTF-8 string, use hexToBytes instead.
If the value is a bigint, it is assumed to be unsigned. To convert a signed
bigint to bytes, use signedBigIntToBytes instead.
If the value is a Uint8Array, it will be returned as-is.
Convert a byte-like value to a
Uint8Array
. The value can be aUint8Array
, abigint
, anumber
, or astring
.This will attempt to guess the type of the value based on its type and contents. For more control over the conversion, use the more specific conversion functions, such as hexToBytes or stringToBytes.
If the value is a
string
, and it is prefixed with0x
, it will be interpreted as a hexadecimal string. Otherwise, it will be interpreted as a UTF-8 string. To convert a hexadecimal string to bytes without interpreting it as a UTF-8 string, use hexToBytes instead.If the value is a
bigint
, it is assumed to be unsigned. To convert a signedbigint
to bytes, use signedBigIntToBytes instead.If the value is a
Uint8Array
, it will be returned as-is.Returns
The bytes as
Uint8Array
.