> ## 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.

# BrandedBytes

> Auto-generated API documentation

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

***

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

# BrandedBytes

## Classes

### InvalidBytesFormatError

Defined in: [src/primitives/Bytes/errors.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L13)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidBytesFormatError**(`message`, `details?`): [`InvalidBytesFormatError`](#invalidbytesformaterror)

Defined in: [src/primitives/Bytes/errors.js:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L18)

###### Parameters

###### message

`string`

###### details?

`any`

###### Returns

[`InvalidBytesFormatError`](#invalidbytesformaterror)

###### Overrides

`Error.constructor`

#### Properties

##### details

> **details**: `any`

Defined in: [src/primitives/Bytes/errors.js:21](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L21)

##### name

> **name**: `string`

Defined in: [src/primitives/Bytes/errors.js:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L20)

###### Inherited from

`Error.name`

***

### InvalidBytesLengthError

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

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidBytesLengthError**(`message`, `details?`): [`InvalidBytesLengthError`](#invalidbyteslengtherror)

Defined in: [src/primitives/Bytes/errors.js:6](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L6)

###### Parameters

###### message

`string`

###### details?

`any`

###### Returns

[`InvalidBytesLengthError`](#invalidbyteslengtherror)

###### Overrides

`Error.constructor`

#### Properties

##### details

> **details**: `any`

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

##### name

> **name**: `string`

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

###### Inherited from

`Error.name`

***

### InvalidValueError

Defined in: [src/primitives/Bytes/errors.js:25](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/errors.js#L25)

#### Extends

* `Error`

#### Constructors

##### Constructor

> **new InvalidValueError**(`message`, `details?`): [`InvalidValueError`](#invalidvalueerror)

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

###### Parameters

###### message

`string`

###### details?

`any`

###### Returns

[`InvalidValueError`](#invalidvalueerror)

###### Overrides

`Error.constructor`

#### Properties

##### details

> **details**: `any`

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

##### name

> **name**: `string`

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

###### Inherited from

`Error.name`

## Variables

### BytesType

> `const` **BytesType**: `object`

Defined in: [src/primitives/Bytes/Bytes.index.ts:59](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/Bytes.index.ts#L59)

#### Type Declaration

##### assert()

> **assert**: (`value`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Assert that value is valid Bytes, throw if not

###### Parameters

###### value

`unknown`

Value to check

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

The validated bytes

###### Throws

If value is not valid Bytes

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
const bytes = Bytes.assert(new Uint8Array([1, 2, 3])); // returns bytes
Bytes.assert("not bytes"); // throws Error
```

##### clone()

> **clone**: (`bytes`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Clone Bytes

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to clone

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Cloned Bytes

###### Example

```typescript theme={null}
const copy = Bytes.clone(bytes);
```

##### compare()

> **compare**: (`a`, `b`) => `number`

Compare two Bytes (lexicographic)

###### Parameters

###### a

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

First Bytes

###### b

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Second Bytes

###### Returns

`number`

-1 if a \< b, 0 if equal, 1 if a > b

###### Example

```typescript theme={null}
const cmp = Bytes.compare(bytes1, bytes2);
```

##### concat()

> **concat**: (...`arrays`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Concatenate multiple Bytes

###### Parameters

###### arrays

...[`BytesType`](../../primitives/Bytes.mdx#bytestype)\[]

Bytes to concatenate

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Concatenated Bytes

###### Example

```typescript theme={null}
const result = Bytes.concat(bytes1, bytes2, bytes3);
```

##### equals()

> **equals**: (`a`, `b`) => `boolean`

Check if two Bytes are equal

###### Parameters

###### a

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

First Bytes

###### b

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Second Bytes

###### Returns

`boolean`

True if equal

###### Example

```typescript theme={null}
const equal = Bytes.equals(bytes1, bytes2);
```

##### from()

> **from**: (`value`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Create Bytes from various input types (universal constructor)

###### Parameters

###### value

Uint8Array, hex string, UTF-8 string, or number array

`string` | `Uint8Array`\<`ArrayBufferLike`> | `number`\[]

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Throws

If value type is unsupported or invalid

###### Example

```typescript theme={null}
const b1 = Bytes.from(new Uint8Array([0x01, 0x02]));
const b2 = Bytes.from("0x1234");
const b3 = Bytes.from("hello");
const b4 = Bytes.from([0x01, 0x02, 0x03]);
```

##### fromBigInt()

> **fromBigInt**: (`value`, `size?`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Convert bigint to Bytes

###### Parameters

###### value

`bigint`

BigInt to convert (must be non-negative)

###### size?

`number`

Optional byte size (pads or throws if too small)

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Throws

If value is negative or doesn't fit in size

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.fromBigInt(255n);      // Uint8Array([0xff])
Bytes.fromBigInt(255n, 2);   // Uint8Array([0x00, 0xff])
Bytes.fromBigInt(0x1234n);   // Uint8Array([0x12, 0x34])
```

##### fromHex()

> **fromHex**: (`hex`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Create Bytes from hex string

###### Parameters

###### hex

`string`

Hex string with 0x prefix

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Throws

If hex string is invalid

###### Example

```typescript theme={null}
const bytes = Bytes.fromHex("0x1234");
// Uint8Array([0x12, 0x34])
```

##### fromNumber()

> **fromNumber**: (`value`, `size?`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Convert number to Bytes

###### Parameters

###### value

`number`

Number to convert (must be safe integer, non-negative)

###### size?

`number`

Optional byte size (pads or throws if too small)

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Throws

If value is negative, not an integer, or exceeds MAX\_SAFE\_INTEGER

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.fromNumber(255);     // Uint8Array([0xff])
Bytes.fromNumber(255, 2);  // Uint8Array([0x00, 0xff])
Bytes.fromNumber(0x1234);  // Uint8Array([0x12, 0x34])
```

##### fromString()

> **fromString**: (`str`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Create Bytes from UTF-8 string

###### Parameters

###### str

`string`

UTF-8 string

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Example

```typescript theme={null}
const bytes = Bytes.fromString("hello");
// Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])
```

##### isBytes()

> **isBytes**: (`value`) => `value is BytesType`

Check if value is a valid Bytes (Uint8Array)

###### Parameters

###### value

`unknown`

Value to check

###### Returns

`value is BytesType`

True if value is Uint8Array

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.isBytes(new Uint8Array([1, 2, 3])); // true
Bytes.isBytes([1, 2, 3]);                  // false
Bytes.isBytes("0x1234");                   // false
```

##### isEmpty()

> **isEmpty**: (`bytes`) => `boolean`

Check if Bytes is empty

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to check

###### Returns

`boolean`

True if empty

###### Example

```typescript theme={null}
const empty = Bytes.isEmpty(bytes);
```

##### padLeft()

> **padLeft**: (`bytes`, `targetSize`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Pad Bytes on the left (start) with zeros to target size

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to pad

###### targetSize

`number`

Target size in bytes

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Padded bytes

###### Throws

If bytes exceeds target size

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.padLeft(new Uint8Array([0x12, 0x34]), 4); // Uint8Array([0x00, 0x00, 0x12, 0x34])
```

##### padRight()

> **padRight**: (`bytes`, `targetSize`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Pad Bytes on the right (end) with zeros to target size

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to pad

###### targetSize

`number`

Target size in bytes

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Padded bytes

###### Throws

If bytes exceeds target size

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.padRight(new Uint8Array([0x12, 0x34]), 4); // Uint8Array([0x12, 0x34, 0x00, 0x00])
```

##### random()

> **random**: (`size`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Generate random Bytes of specified size

###### Parameters

###### size

`number`

Number of random bytes to generate

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Random bytes

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
const random32 = Bytes.random(32); // 32 random bytes
const random16 = Bytes.random(16); // 16 random bytes
```

##### size()

> **size**: (`bytes`) => `number`

Get size of Bytes

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

###### Returns

`number`

Size in bytes

###### Example

```typescript theme={null}
const size = Bytes.size(bytes);
```

##### slice()

> **slice**: (`bytes`, `start`, `end?`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Slice Bytes

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to slice

###### start

`number`

Start index

###### end?

`number`

End index (optional)

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Sliced Bytes

###### Example

```typescript theme={null}
const slice = Bytes.slice(bytes, 0, 4);
```

##### toBigInt()

> **toBigInt**: (`bytes`) => `bigint`

Convert Bytes to bigint

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

###### Returns

`bigint`

BigInt value

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.toBigInt(new Uint8Array([0xff]));       // 255n
Bytes.toBigInt(new Uint8Array([0x12, 0x34])); // 4660n
```

##### toHex()

> **toHex**: (`bytes`) => [`HexType`](../../primitives/Hex.mdx#hextype)

Convert Bytes to hex string

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

###### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string with 0x prefix

###### Example

```typescript theme={null}
const hex = Bytes.toHex(bytes);
// "0x1234"
```

##### toNumber()

> **toNumber**: (`bytes`) => `number`

Convert Bytes to number

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

###### Returns

`number`

Number value

###### Throws

If value exceeds MAX\_SAFE\_INTEGER

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.toNumber(new Uint8Array([0xff]));       // 255
Bytes.toNumber(new Uint8Array([0x12, 0x34])); // 4660
```

##### toString()

> **toString**: (`bytes`) => `string`

Convert Bytes to UTF-8 string

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

###### Returns

`string`

UTF-8 string

###### Example

```typescript theme={null}
const str = Bytes.toString(bytes);
// "hello"
```

##### trimLeft()

> **trimLeft**: (`bytes`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trim leading zeros from Bytes

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to trim

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trimmed bytes

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.trimLeft(new Uint8Array([0x00, 0x00, 0x12, 0x34])); // Uint8Array([0x12, 0x34])
Bytes.trimLeft(new Uint8Array([0x00, 0x00, 0x00]));       // Uint8Array([])
```

##### trimRight()

> **trimRight**: (`bytes`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trim trailing zeros from Bytes

###### Parameters

###### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to trim

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trimmed bytes

###### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.trimRight(new Uint8Array([0x12, 0x34, 0x00, 0x00])); // Uint8Array([0x12, 0x34])
Bytes.trimRight(new Uint8Array([0x00, 0x00, 0x00]));       // Uint8Array([])
```

##### zero()

> **zero**: (`size`) => [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Create zero Bytes of specified size

###### Parameters

###### size

`number`

Size in bytes

###### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Zero Bytes

###### Example

```typescript theme={null}
const zeros = Bytes.zero(32);
```

## Functions

### assert()

> **assert**(`value`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/assert.js:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/assert.js#L17)

Assert that value is valid Bytes, throw if not

#### Parameters

##### value

`unknown`

Value to check

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

The validated bytes

#### Throws

If value is not valid Bytes

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
const bytes = Bytes.assert(new Uint8Array([1, 2, 3])); // returns bytes
Bytes.assert("not bytes"); // throws Error
```

***

### clone()

> **clone**(`bytes`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/clone.js:12](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/clone.js#L12)

Clone Bytes

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to clone

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Cloned Bytes

#### Example

```typescript theme={null}
const copy = Bytes.clone(bytes);
```

***

### compare()

> **compare**(`a`, `b`): `number`

Defined in: [src/primitives/Bytes/compare.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/compare.js#L13)

Compare two Bytes (lexicographic)

#### Parameters

##### a

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

First Bytes

##### b

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Second Bytes

#### Returns

`number`

-1 if a \< b, 0 if equal, 1 if a > b

#### Example

```typescript theme={null}
const cmp = Bytes.compare(bytes1, bytes2);
```

***

### concat()

> **concat**(...`arrays`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/concat.js:12](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/concat.js#L12)

Concatenate multiple Bytes

#### Parameters

##### arrays

...[`BytesType`](../../primitives/Bytes.mdx#bytestype)\[]

Bytes to concatenate

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Concatenated Bytes

#### Example

```typescript theme={null}
const result = Bytes.concat(bytes1, bytes2, bytes3);
```

***

### equals()

> **equals**(`a`, `b`): `boolean`

Defined in: [src/primitives/Bytes/equals.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/equals.js#L13)

Check if two Bytes are equal

#### Parameters

##### a

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

First Bytes

##### b

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Second Bytes

#### Returns

`boolean`

True if equal

#### Example

```typescript theme={null}
const equal = Bytes.equals(bytes1, bytes2);
```

***

### from()

> **from**(`value`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/from.js:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/from.js#L20)

Create Bytes from various input types (universal constructor)

#### Parameters

##### value

Uint8Array, hex string, UTF-8 string, or number array

`string` | `Uint8Array`\<`ArrayBufferLike`> | `number`\[]

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Throws

If value type is unsupported or invalid

#### Example

```typescript theme={null}
const b1 = Bytes.from(new Uint8Array([0x01, 0x02]));
const b2 = Bytes.from("0x1234");
const b3 = Bytes.from("hello");
const b4 = Bytes.from([0x01, 0x02, 0x03]);
```

***

### fromBigInt()

> **fromBigInt**(`value`, `size?`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/fromBigInt.js:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/fromBigInt.js#L17)

Convert bigint to Bytes

#### Parameters

##### value

`bigint`

BigInt to convert (must be non-negative)

##### size?

`number`

Optional byte size (pads or throws if too small)

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Throws

If value is negative or doesn't fit in size

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.fromBigInt(255n);      // Uint8Array([0xff])
Bytes.fromBigInt(255n, 2);   // Uint8Array([0x00, 0xff])
Bytes.fromBigInt(0x1234n);   // Uint8Array([0x12, 0x34])
```

***

### fromHex()

> **fromHex**(`hex`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/fromHex.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/fromHex.js#L16)

Create Bytes from hex string

#### Parameters

##### hex

`string`

Hex string with 0x prefix

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Throws

If hex string is invalid

#### Example

```typescript theme={null}
const bytes = Bytes.fromHex("0x1234");
// Uint8Array([0x12, 0x34])
```

***

### fromNumber()

> **fromNumber**(`value`, `size?`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/fromNumber.js:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/fromNumber.js#L17)

Convert number to Bytes

#### Parameters

##### value

`number`

Number to convert (must be safe integer, non-negative)

##### size?

`number`

Optional byte size (pads or throws if too small)

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Throws

If value is negative, not an integer, or exceeds MAX\_SAFE\_INTEGER

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.fromNumber(255);     // Uint8Array([0xff])
Bytes.fromNumber(255, 2);  // Uint8Array([0x00, 0xff])
Bytes.fromNumber(0x1234);  // Uint8Array([0x12, 0x34])
```

***

### fromString()

> **fromString**(`str`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/fromString.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/fromString.js#L13)

Create Bytes from UTF-8 string

#### Parameters

##### str

`string`

UTF-8 string

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Example

```typescript theme={null}
const bytes = Bytes.fromString("hello");
// Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f])
```

***

### isBytes()

> **isBytes**(`value`): `value is BytesType`

Defined in: [src/primitives/Bytes/isBytes.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/isBytes.js#L15)

Check if value is a valid Bytes (Uint8Array)

#### Parameters

##### value

`unknown`

Value to check

#### Returns

`value is BytesType`

True if value is Uint8Array

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.isBytes(new Uint8Array([1, 2, 3])); // true
Bytes.isBytes([1, 2, 3]);                  // false
Bytes.isBytes("0x1234");                   // false
```

***

### isEmpty()

> **isEmpty**(`bytes`): `boolean`

Defined in: [src/primitives/Bytes/isEmpty.js:12](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/isEmpty.js#L12)

Check if Bytes is empty

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to check

#### Returns

`boolean`

True if empty

#### Example

```typescript theme={null}
const empty = Bytes.isEmpty(bytes);
```

***

### padLeft()

> **padLeft**(`bytes`, `targetSize`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/padLeft.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/padLeft.js#L15)

Pad Bytes on the left (start) with zeros to target size

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to pad

##### targetSize

`number`

Target size in bytes

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Padded bytes

#### Throws

If bytes exceeds target size

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.padLeft(new Uint8Array([0x12, 0x34]), 4); // Uint8Array([0x00, 0x00, 0x12, 0x34])
```

***

### padRight()

> **padRight**(`bytes`, `targetSize`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/padRight.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/padRight.js#L15)

Pad Bytes on the right (end) with zeros to target size

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to pad

##### targetSize

`number`

Target size in bytes

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Padded bytes

#### Throws

If bytes exceeds target size

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.padRight(new Uint8Array([0x12, 0x34]), 4); // Uint8Array([0x12, 0x34, 0x00, 0x00])
```

***

### random()

> **random**(`size`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/random.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/random.js#L14)

Generate random Bytes of specified size

#### Parameters

##### size

`number`

Number of random bytes to generate

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Random bytes

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
const random32 = Bytes.random(32); // 32 random bytes
const random16 = Bytes.random(16); // 16 random bytes
```

***

### size()

> **size**(`bytes`): `number`

Defined in: [src/primitives/Bytes/size.js:12](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/size.js#L12)

Get size of Bytes

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes

#### Returns

`number`

Size in bytes

#### Example

```typescript theme={null}
const size = Bytes.size(bytes);
```

***

### slice()

> **slice**(`bytes`, `start`, `end?`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/slice.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/slice.js#L14)

Slice Bytes

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to slice

##### start

`number`

Start index

##### end?

`number`

End index (optional)

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Sliced Bytes

#### Example

```typescript theme={null}
const slice = Bytes.slice(bytes, 0, 4);
```

***

### toBigInt()

> **toBigInt**(`bytes`): `bigint`

Defined in: [src/primitives/Bytes/toBigInt.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/toBigInt.js#L14)

Convert Bytes to bigint

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

#### Returns

`bigint`

BigInt value

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.toBigInt(new Uint8Array([0xff]));       // 255n
Bytes.toBigInt(new Uint8Array([0x12, 0x34])); // 4660n
```

***

### toHex()

> **toHex**(`bytes`): [`HexType`](../../primitives/Hex.mdx#hextype)

Defined in: [src/primitives/Bytes/toHex.js:13](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/toHex.js#L13)

Convert Bytes to hex string

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

#### Returns

[`HexType`](../../primitives/Hex.mdx#hextype)

Hex string with 0x prefix

#### Example

```typescript theme={null}
const hex = Bytes.toHex(bytes);
// "0x1234"
```

***

### toNumber()

> **toNumber**(`bytes`): `number`

Defined in: [src/primitives/Bytes/toNumber.js:15](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/toNumber.js#L15)

Convert Bytes to number

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

#### Returns

`number`

Number value

#### Throws

If value exceeds MAX\_SAFE\_INTEGER

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.toNumber(new Uint8Array([0xff]));       // 255
Bytes.toNumber(new Uint8Array([0x12, 0x34])); // 4660
```

***

### toString()

> **toString**(`bytes`): `string`

Defined in: [src/primitives/Bytes/toString.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/toString.js#L14)

Convert Bytes to UTF-8 string

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to convert

#### Returns

`string`

UTF-8 string

#### Example

```typescript theme={null}
const str = Bytes.toString(bytes);
// "hello"
```

***

### trimLeft()

> **trimLeft**(`bytes`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/trimLeft.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/trimLeft.js#L14)

Trim leading zeros from Bytes

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to trim

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trimmed bytes

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.trimLeft(new Uint8Array([0x00, 0x00, 0x12, 0x34])); // Uint8Array([0x12, 0x34])
Bytes.trimLeft(new Uint8Array([0x00, 0x00, 0x00]));       // Uint8Array([])
```

***

### trimRight()

> **trimRight**(`bytes`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/trimRight.js:14](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/trimRight.js#L14)

Trim trailing zeros from Bytes

#### Parameters

##### bytes

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Bytes to trim

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Trimmed bytes

#### Example

```javascript theme={null}
import * as Bytes from './primitives/Bytes/index.js';
Bytes.trimRight(new Uint8Array([0x12, 0x34, 0x00, 0x00])); // Uint8Array([0x12, 0x34])
Bytes.trimRight(new Uint8Array([0x00, 0x00, 0x00]));       // Uint8Array([])
```

***

### zero()

> **zero**(`size`): [`BytesType`](../../primitives/Bytes.mdx#bytestype)

Defined in: [src/primitives/Bytes/zero.js:12](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Bytes/zero.js#L12)

Create zero Bytes of specified size

#### Parameters

##### size

`number`

Size in bytes

#### Returns

[`BytesType`](../../primitives/Bytes.mdx#bytestype)

Zero Bytes

#### Example

```typescript theme={null}
const zeros = Bytes.zero(32);
```
