> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nanoforge.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# definePacket

> Declare a packet type.

> **definePacket**\<`T`>(`name`, `options?`): [`PacketDefinition`](https://docs.nanoforge.eu/references/engine/3.0.0/network/index/interfaces/PacketDefinition)\<`T`>

Defined in: [modules/network/src/shared/packet.ts:72](https://github.com/NanoForge-dev/Engine/blob/ed8c7e0b33d17f8343c32659cf63ba4166a4fa53/modules/network/src/shared/packet.ts#L72)

Declare a packet type.

## Type Parameters

### T

`T` = `void`

## Parameters

### name

`string`

Name identifying the type on the wire, unique in the game.

### options?

[`PacketOptions`](https://docs.nanoforge.eu/references/engine/3.0.0/network/index/type-aliases/PacketOptions)\<`T`> = `{}`

Default `channel` and payload `validate` check.

## Returns

[`PacketDefinition`](https://docs.nanoforge.eu/references/engine/3.0.0/network/index/interfaces/PacketDefinition)\<`T`>

The packet definition, used by `packets.on`, `read` and `send`.

## Example

```ts theme={null}
// protocol.ts, imported by the client and the server
export const Move = definePacket<{ id: number; x: number; y: number }>("move", {
  channel: Channel.UnreliableOrdered,
});
export const Play = definePacket("play"); // no payload: `send(Play)`
```

## Throws

When the name is empty or longer than 255 UTF-8 bytes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.