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

# Rlp.encodeTo

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

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

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

## Examples

```ts twoslash
// @noErrors
import { Bytes, Rlp } from 'viem/utils'

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
```

## 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`
