# Bytes.fromString

Encodes a string into [`Bytes.Bytes`](/api/Bytes/types#bytes).

## Imports

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

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

## Examples

```ts twoslash
import { Bytes } from 'ox'

const data = Bytes.fromString('Hello world!')
// @log: Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
```

```ts twoslash
import { Bytes } from 'ox'

const data = Bytes.fromString('Hello world!', { size: 32 })
// @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
```

## Definition

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

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

## Parameters

### value

* **Type:** `string`

String to encode.

### options

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

Encoding options.

#### options.size

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

Size of the output bytes.

## Return Type

Encoded [`Bytes.Bytes`](/api/Bytes/types#bytes).

`Bytes`
