39 lines
973 B
Markdown
39 lines
973 B
Markdown
|
|
|
|
# Functions
|
|
|
|
<a id="hextou8a"></a>
|
|
|
|
## hexToU8a
|
|
|
|
▸ **hexToU8a**(_value?: *`string` \| `null`*, bitLength?: *`number`*): `Uint8Array`
|
|
|
|
*Defined in [hex/toU8a.ts:24](https://github.com/polkadot-js/common/blob/6506c10/packages/util/src/hex/toU8a.ts#L24)*
|
|
|
|
*__name__*: hexToU8a
|
|
|
|
*__summary__*: Creates a Buffer object from a hex string.
|
|
|
|
*__description__*: `null` inputs returns an empty `Uint8Array` result. Hex input values return the actual bytes value converted to a Uint8Array. Anything that is not a hex string (including the `0x` prefix) throws an error.
|
|
|
|
*__example__*:
|
|
|
|
```javascript
|
|
import { hexToU8a } from '@polkadot/util';
|
|
|
|
hexToU8a('0x80001f'); // Uint8Array([0x80, 0x00, 0x1f])
|
|
hexToU8a('0x80001f', 32); // Uint8Array([0x00, 0x80, 0x00, 0x1f])
|
|
```
|
|
|
|
**Parameters:**
|
|
|
|
| Name | Type | Default value |
|
|
| ------ | ------ | ------ |
|
|
| `Optional` _value | `string` \| `null` | - |
|
|
| `Default value` bitLength | `number` | -1 |
|
|
|
|
**Returns:** `Uint8Array`
|
|
|
|
___
|
|
|