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

# Hex.toBytes

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

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

## Imports

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

## Examples

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

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

## Definition

```ts
function toBytes(
  hex: Hex,
  options?: toBytes.Options,
): Uint8Array
```

## Parameters

### hex

* **Type:** `Hex`

The [`Hex.Hex`](/docs/utilities/hex/types#hex) value to decode.

### options

* **Type:** `toBytes.Options`
* **Optional**

Options.

#### options.size

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

Size (in bytes) of the hex value.

## Return Type

The decoded [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes).

`Uint8Array`
