# Bytes.fromHex

Encodes a [`Hex.Hex`](/api/Hex/types#hex) value into [`Bytes.Bytes`](/api/Bytes/types#bytes).

## Imports

:::code-group
```ts [Named]
import { Bytes } from 'ox'
```

```ts [Entrypoint]
import * as Bytes from 'ox/Bytes'
```
:::

## Examples

```ts twoslash
import { Bytes } from 'ox'

const data = Bytes.fromHex('0x48656c6c6f20776f726c6421')
// @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
```

```ts twoslash
import { Bytes } from 'ox'

const data = Bytes.fromHex('0x48656c6c6f20776f726c6421', {
  size: 32
})
// @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
```

## Definition

```ts
function fromHex(
  value: Hex.Hex,
  options?: fromHex.Options,
): Bytes
```

**Source:** [src/core/Bytes.ts](https://github.com/wevm/ox/blob/main/src/core/Bytes.ts#L890)

## Parameters

### value

* **Type:** `Hex.Hex`

[`Hex.Hex`](/api/Hex/types#hex) value to encode.

### options

* **Type:** `fromHex.Options`
* **Optional**

Encoding options.

#### options.size

* **Type:** `number`
* **Optional**

Size of the output bytes.

## Return Type

Encoded [`Bytes.Bytes`](/api/Bytes/types#bytes).

`Bytes`
