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

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

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

## Imports

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

## Examples

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

Bytes.toHex(
  Bytes.from([
    72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33
  ])
)
// '0x48656c6c6f20576f726c6421'
```

## Definition

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

## Parameters

### value

* **Type:** `Bytes`

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

### options

* **Type:** `toHex.Options`
* **Optional**

Options.

#### options.size

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

Size of the bytes.

## Return Type

Decoded [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

`Hex.Hex`
