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

# PersonalMessage.encode

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

Encodes a personal sign message in [ERC-191 format](https://eips.ethereum.org/EIPS/eip-191#version-0x45-e): `0x19 ‖ "Ethereum Signed Message:\n" + message.length ‖ message`.

## Imports

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

## Examples

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

const data = PersonalMessage.encode(
  Hex.fromString('hello world')
)
// @log: '0x19457468657265756d205369676e6564204d6573736167653a0a313168656c6c6f20776f726c64'
// @log: (0x19 ‖ 'Ethereum Signed Message:\n11' ‖ 'hello world')
```

## Definition

```ts
function encode(
  data: Hex.Hex | Bytes.Bytes,
): Hex.Hex
```

## Parameters

### data

* **Type:** `Hex.Hex | Bytes.Bytes`

The data to encode.

## Return Type

The encoded personal sign message.

`Hex.Hex`
