Blockchain Commons Components TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Function hexToBytes

    • Convert a hexadecimal string to a Uint8Array.

      Parameters

      • hex: string

        A hex string (must have even length, case-insensitive)

      Returns Uint8Array

      The decoded byte array

      If the hex string has odd length or contains invalid characters

      hexToBytes("deadbeef"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])
      hexToBytes("DEADBEEF"); // Uint8Array([0xde, 0xad, 0xbe, 0xef])
      hexToBytes("xyz"); // throws Error: Invalid hex string