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

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

Utility functions for encoding and decoding [Recursive Length Prefix](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) structures.

## Examples

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

const data = Rlp.fromHex([
  Hex.fromString('hello'),
  Hex.fromString('world')
])
// @log: '0xcc8568656c6c6f85776f726c64'

const values = Rlp.toHex(data)
// @log: [Hex.fromString('hello'), Hex.fromString('world')]
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Rlp.encodeTo`](/docs/utilities/rlp/encodeTo) | Encodes a value as Recursive-Length Prefix (RLP) and writes the encoded bytes through a synchronous callback without allocating the complete encoding. |
| [`Rlp.from`](/docs/utilities/rlp/from) | Encodes a [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) or [`Hex.Hex`](/docs/utilities/hex/types#hex) value into a Recursive-Length Prefix (RLP) value. |
| [`Rlp.fromBytes`](/docs/utilities/rlp/fromBytes) | Encodes a [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) value into a Recursive-Length Prefix (RLP) value. |
| [`Rlp.fromHex`](/docs/utilities/rlp/fromHex) | Encodes a [`Hex.Hex`](/docs/utilities/hex/types#hex) value into a Recursive-Length Prefix (RLP) value. |
| [`Rlp.toBytes`](/docs/utilities/rlp/toBytes) | Decodes a Recursive-Length Prefix (RLP) value into a [`Bytes.Bytes`](/docs/utilities/bytes/types#bytes) value. |
| [`Rlp.toHex`](/docs/utilities/rlp/toHex) | Decodes a Recursive-Length Prefix (RLP) value into a [`Hex.Hex`](/docs/utilities/hex/types#hex) value. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Rlp.DepthLimitExceededError`](/docs/utilities/rlp/errors#rlpdepthlimitexceedederror) | Thrown when an RLP value nests deeper than the decode depth limit. |
| [`Rlp.ListBoundaryExceededError`](/docs/utilities/rlp/errors#rlplistboundaryexceedederror) | Thrown when RLP list items overrun the list's declared length. |
| [`Rlp.TrailingBytesError`](/docs/utilities/rlp/errors#rlptrailingbyteserror) | Thrown when an RLP payload contains bytes after the decoded item. |
