> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Bytes.fromHex

:::info
`Bytes.fromHex` is a re-export of ox's [`Bytes.fromHex`](https://oxlib.sh/api/Bytes/fromHex). Refer to the ox documentation for the full reference.
:::

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

## Imports

```ts
import { Bytes } from 'viem/utils'
```

## Examples

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

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

```ts twoslash
// @noErrors
import { Bytes } from 'viem/utils'

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
```

## Parameters

### value

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

[`Hex.Hex`](/docs/utilities/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`](/docs/utilities/bytes/types#bytes).

`Bytes`
