# serializeGraph

> **serializeGraph**(`graph`, `options?`): `Uint8Array`

Defined in: [packages/graph/src/serialization.ts:121](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/graph/src/serialization.ts#L121)

Serialize a graph into canonical binary bytes that restore the same layout.

The payload is the graph’s `edges()` columns: sources delta-coded, targets at the smallest width that holds a vertex, and weights as little-endian `float64`, inside a `knotkit/wire` envelope whose header carries the kind, the four flags, and the producer version. Two graphs serialize to equal bytes when they have the same kind, vertex count, flags, and `edges()`, and are written by the same package version with the same `integrity` setting.

## Parameters

### graph

[`Graph`](/reference/knotkit/graph/type-aliases/graph/)

### options?

[`SerializeGraphOptions`](/reference/knotkit/graph/wire/interfaces/serializegraphoptions/)

## Returns

`Uint8Array`

## Throws

With code `FOREIGN_GRAPH` when `graph` was not produced by this package, or `SERIALIZATION_LIMIT_EXCEEDED` when it has more than [GRAPH_MAX_DECODE_VERTICES](/reference/knotkit/graph/wire/variables/graph_max_decode_vertices/) vertices.
