# Hex.fromString

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

## Imports

:::code-group
```ts [Named]
import { Hex } from 'ox'
```

```ts [Entrypoint]
import * as Hex from 'ox/Hex'
```
:::

## Examples

```ts twoslash
import { Hex } from 'ox'
Hex.fromString('Hello World!')
// '0x48656c6c6f20576f726c6421'

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

## Definition

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

**Source:** [src/core/Hex.ts](https://github.com/wevm/ox/blob/main/src/core/Hex.ts#L1003)

## 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`](/api/Hex/types#hex) value.

`Hex`
