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

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

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

## Imports

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

## Examples

```ts twoslash
// @noErrors
import { Hex } from 'viem/utils'
Hex.fromString('Hello World!')
// '0x48656c6c6f20576f726c6421'

Hex.fromString('Hello World!', { size: 32 })
// '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000'
```

## Definition

```ts
function fromString(
  value: string,
  options?: fromString.Options,
): Hex
```

## Parameters

### value

* **Type:** `string`

The string value to encode.

### options

* **Type:** `fromString.Options`
* **Optional**

Options.

#### options.size

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

The size (in bytes) of the output hex value.

## Return Type

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

`Hex`
