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

# PublicKey.fromHex

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

Deserializes a [`PublicKey.PublicKey`](/docs/utilities/publickey/types#publickey) from a [`Hex.Hex`](/docs/utilities/hex/types#hex) value.

## Imports

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

## Examples

```ts twoslash
// @noErrors
import { PublicKey } from 'viem/utils'

const publicKey = PublicKey.fromHex(
  '0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5'
)
// @log: {
// @log:   prefix: 4,
// @log:   x: '0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75',
// @log:   y: '0x3547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5',
// @log: }
```

### Deserializing a Compressed Public Key

```ts twoslash
// @noErrors
import { PublicKey } from 'viem/utils'

const publicKey = PublicKey.fromHex(
  '0x038318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75'
)
// @log: {
// @log:   prefix: 3,
// @log:   x: '0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75',
// @log: }
```

## Definition

```ts
function fromHex(
  publicKey: Hex.Hex,
): PublicKey
```

## Parameters

### publicKey

* **Type:** `Hex.Hex`

The serialized public key.

## Return Type

The deserialized public key.

`PublicKey`
