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

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

Compresses a [`PublicKey.PublicKey`](/docs/utilities/publickey/types#publickey).

## Imports

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

## Examples

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

const publicKey = PublicKey.from({
  prefix: 4,
  x: '0x83185...',
  y: '0x35477...'
})

const compressed = PublicKey.compress(publicKey) // [!code focus]
// @log: {
// @log:   prefix: 3,
// @log:   x: '0x83185...',
// @log: }
```

## Definition

```ts
function compress(
  publicKey: PublicKey<false>,
): PublicKey<true>
```

## Parameters

### publicKey

* **Type:** `PublicKey<false>`

The public key to compress.

#### publicKey.prefix

* **Type:** `numberType`

#### publicKey.x

* **Type:** `0x${string}`

#### publicKey.y

* **Type:** `0x${string}`

## Return Type

The compressed public key.

`PublicKey<true>`
