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

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

Instantiates a [`Hex.Hex`](/docs/utilities/hex/types#hex) value from a hex string or [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) value.

:::tip
To instantiate from a **Boolean**, **String**, or **Number**, use one of the following:

* `Hex.fromBoolean`

* `Hex.fromString`

* `Hex.fromNumber`
:::

## Imports

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

## Examples

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

Hex.from('0x48656c6c6f20576f726c6421')
// @log: '0x48656c6c6f20576f726c6421'

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

## Definition

```ts
function from(
  value: Hex | Uint8Array | readonly number[],
): Hex
```

## Parameters

### value

* **Type:** `Hex | Uint8Array | readonly number[]`

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

## Return Type

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

`Hex`
