# Rlp.encodeTo

Encodes a value as Recursive-Length Prefix (RLP) and writes the encoded bytes through a synchronous callback without allocating the complete encoding.

Ox validates the complete input before the first write. If the callback throws, the error propagates and earlier callback side effects remain.

Ox does not mutate a chunk after the callback returns. A chunk may alias a byte-array leaf from the encoded value. The callback must not mutate the chunk before `encodeTo` returns.

## Imports

:::code-group
```ts [Named]
import { Rlp } from 'ox'
```

```ts [Entrypoint]
import * as Rlp from 'ox/Rlp'
```
:::

## Examples

```ts twoslash
import { Bytes, Rlp } from 'ox'

const chunks: Uint8Array[] = []
Rlp.encodeTo(['0x01', '0x0203'], (chunk) => {
  chunks.push(chunk)
})

const encoded = Bytes.concat(...chunks)
// @log: Uint8Array([196, 1, 130, 2, 3])
```

## Definition

```ts
function encodeTo(
  value: RecursiveArray<Bytes.Bytes> | RecursiveArray<Hex.Hex>,
  write: (chunk: Bytes.Bytes) => undefined,
): void
```

**Source:** [src/core/Rlp.ts](https://github.com/wevm/ox/blob/main/src/core/Rlp.ts#L223)

## Parameters

### value

* **Type:** `RecursiveArray<Bytes.Bytes> | RecursiveArray<Hex.Hex>`

The bytes or Hex value, or nested list of values, to encode.

### write

* **Type:** `(chunk: Bytes.Bytes) => undefined`

The synchronous callback for encoded chunks.

## Return Type

Nothing.

`void`
