> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# primitives/Hex

> Auto-generated API documentation

[**@tevm/voltaire**](../index.mdx)

***

[@tevm/voltaire](../index.mdx) / primitives/Hex

# primitives/Hex

## Classes

### InvalidCharacterError

Defined in: [src/primitives/Hex/errors.ts:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L15)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidCharacterError**(`message`): [`InvalidCharacterError`](#invalidcharactererror)

Defined in: [src/primitives/Hex/errors.ts:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L16)

###### Parameters

###### message

`string` = `"Invalid hex character"`

###### Returns

[`InvalidCharacterError`](#invalidcharactererror)

###### Overrides

`Error.constructor`

***

### InvalidFormatError

Defined in: [src/primitives/Hex/errors.ts:1](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L1)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidFormatError**(`message`): [`InvalidFormatError`](#invalidformaterror)

Defined in: [src/primitives/Hex/errors.ts:2](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L2)

###### Parameters

###### message

`string` = `"Invalid hex format: missing 0x prefix"`

###### Returns

[`InvalidFormatError`](#invalidformaterror)

###### Overrides

`Error.constructor`

***

### InvalidLengthError

Defined in: [src/primitives/Hex/errors.ts:8](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L8)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidLengthError**(`message`): [`InvalidLengthError`](#invalidlengtherror)

Defined in: [src/primitives/Hex/errors.ts:9](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L9)

###### Parameters

###### message

`string` = `"Invalid hex length"`

###### Returns

[`InvalidLengthError`](#invalidlengtherror)

###### Overrides

`Error.constructor`

***

### OddLengthError

Defined in: [src/primitives/Hex/errors.ts:22](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L22)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new OddLengthError**(`message`): [`OddLengthError`](#oddlengtherror)

Defined in: [src/primitives/Hex/errors.ts:23](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L23)

###### Parameters

###### message

`string` = `"Odd length hex string"`

###### Returns

[`OddLengthError`](#oddlengtherror)

###### Overrides

`Error.constructor`

## Type Aliases

### Bytes

> **Bytes**\<`N`> = [`Sized`](#sized)\<`N`>

Defined in: [src/primitives/Hex/HexType.ts:25](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/HexType.ts#L25)

Hex string of exactly N bytes

#### Type Parameters

##### N

`N` *extends* `number`

***

### HexBrand

> **HexBrand** = [`HexType`](#hextype)

Defined in: [src/primitives/Hex/HexType.ts:11](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/HexType.ts#L11)

Alias for HexType

***

### HexType

> **HexType** = `` `0x${string}` `` & `object`

Defined in: [src/primitives/Hex/HexType.ts:6](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/HexType.ts#L6)

Branded Hex type (unsized)

#### Type Declaration

##### \[brand]

> `readonly` **\[brand]**: `"Hex"`

***

### Sized

> **Sized**\<`TSize`> = `` `0x${string}` `` & `object`

Defined in: [src/primitives/Hex/HexType.ts:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/HexType.ts#L17)

Sized Hex type with specific byte size

#### Type Declaration

##### \[brand]

> `readonly` **\[brand]**: `"Hex"`

##### size

> `readonly` **size**: `TSize`

#### Type Parameters

##### TSize

`TSize` *extends* `number` = `number`

#### Example

```ts theme={null}
HexType.Sized<4> = '0x12345678' (4 bytes = 8 hex chars)
```

## Variables

### fromBytes()

> `const` **fromBytes**: (`bytes`) => [`HexType`](#hextype) = `HexFuncs.fromBytes`

Defined in: [src/primitives/Hex/Hex.ts:8](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/Hex.ts#L8)

Convert bytes to hex

#### Parameters

##### bytes

`Uint8Array`

Byte array to convert

#### Returns

[`HexType`](#hextype)

Hex string

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.fromBytes(new Uint8Array([0x12, 0x34])); // '0x1234'
```

***

### InvalidHexCharacterError

> `const` **InvalidHexCharacterError**: *typeof* [`InvalidCharacterError`](#invalidcharactererror) = `InvalidCharacterError`

Defined in: [src/primitives/Hex/errors.ts:31](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L31)

***

### InvalidHexFormatError

> `const` **InvalidHexFormatError**: *typeof* [`InvalidFormatError`](#invalidformaterror) = `InvalidFormatError`

Defined in: [src/primitives/Hex/errors.ts:30](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L30)

***

### InvalidHexLengthError

> `const` **InvalidHexLengthError**: *typeof* [`InvalidLengthError`](#invalidlengtherror) = `InvalidLengthError`

Defined in: [src/primitives/Hex/errors.ts:33](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L33)

***

### OddLengthHexError

> `const` **OddLengthHexError**: *typeof* [`OddLengthError`](#oddlengtherror) = `OddLengthError`

Defined in: [src/primitives/Hex/errors.ts:32](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/errors.ts#L32)

***

### toBytes()

> `const` **toBytes**: (`hex`) => `Uint8Array` = `HexFuncs.toBytes`

Defined in: [src/primitives/Hex/Hex.ts:9](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hex/Hex.ts#L9)

Convert hex to bytes

#### Parameters

##### hex

Hex string to convert

`string` | [`HexType`](#hextype)

#### Returns

`Uint8Array`

Byte array

#### See

[https://voltaire.tevm.sh/primitives/hex](https://voltaire.tevm.sh/primitives/hex) for Hex documentation

#### Since

0.0.0

#### Throws

If missing 0x prefix or contains invalid hex characters

#### Throws

If hex has odd number of digits

#### Example

```typescript theme={null}
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const bytes = Hex.toBytes(hex); // Uint8Array([0x12, 0x34])
```

## References

### default

Renames and re-exports [Hex](../index/index.mdx#hex)

***

### Hex

Re-exports [Hex](../index/index.mdx#hex)
