# serializeHeap

> **serializeHeap**<`A`>(`heap`, `codec`, `options?`): `Uint8Array`

Defined in: [packages/heap/src/serialization/binary.ts:141](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/heap/src/serialization/binary.ts#L141)

Serialize a heap’s exact internal node order into canonical binary bytes. The caller-supplied order remains outside the artifact.

## Type Parameters

### A

`A`

## Parameters

### heap

[`Heap`](/reference/knotkit/heap/type-aliases/heap/)<`A`>

### codec

[`ElementCodec`](/reference/knotkit/wire/interfaces/elementcodec/)<`A`>

### options?

[`SerializeHeapOptions`](/reference/knotkit/heap/wire/interfaces/serializeheapoptions/)

## Returns

`Uint8Array`

## Throws

With `FOREIGN_STRUCTURE`, `MISSING_ELEMENT_CODEC`, `INVALID_CODEC_RESULT`, `NON_INJECTIVE_CODEC`, or `SERIALIZATION_LIMIT_EXCEEDED` when the input cannot be represented.
