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

# Rlp

> Recursive Length Prefix encoding for Ethereum data structures

> [card] [Try it Live](https://playground.tevm.sh?example=primitives/rlp.ts)
>
> Run RLP examples in the interactive playground

> [!TIP]
>
> New to RLP? Start with [Fundamentals](https://voltaire.tevm.sh/primitives/rlp/fundamentals.md) for guided examples and encoding rules.

## Type Definition

[Branded](https://voltaire.tevm.sh/getting-started/branded-types.md) data structure for RLP-encoded data with type-safe encoding and decoding.

```typescript theme={null}
export type BrandedRlp =
  | { type: "bytes"; value: Uint8Array }
  | { type: "list"; value: BrandedRlp[] };
```

RLP provides deterministic serialization for transactions, blocks, state tries, and network protocols. It encodes only structure (not types), making it space-efficient and fast.

## Quick Reference

## API Methods

### Constructors

* [from](./from) - Create RLP data structures from bytes or nested arrays

### Encoding

* [encode](https://voltaire.tevm.sh/primitives/rlp/encode.md) - Encode bytes, lists, and nested structures
* [encodeBytes](./encode-bytes) - Encode raw bytes to RLP format
* [encodeList](./encode-list) - Encode array of items to RLP list
* [encodeArray](./encode-array) - Encode array with variadic arguments
* [encodeObject](https://voltaire.tevm.sh/primitives/rlp/encode.md) - Encode object to RLP structure
* [encodeVariadic](https://voltaire.tevm.sh/primitives/rlp/encode.md) - Encode multiple arguments
* [encodeBatch](https://voltaire.tevm.sh/primitives/rlp/encode.md) - Batch encode multiple items

### Decoding

* [decode](https://voltaire.tevm.sh/primitives/rlp/decode.md) - Decode RLP bytes to data structures
* [decodeArray](./decode-array) - Decode RLP list to array
* [decodeObject](https://voltaire.tevm.sh/primitives/rlp/decode.md) - Decode RLP to object
* [decodeBatch](https://voltaire.tevm.sh/primitives/rlp/decode.md) - Batch decode multiple RLP items

### Validation

* [validate](./validate) - Validate RLP encoding structure and format

### Utilities

* [getEncodedLength](./get-encoded-length) - Calculate encoded length without encoding
* [getLength](./get-encoded-length) - Get length of RLP item
* [flatten](./flatten) - Flatten nested RLP structure
* [equals](./equals) - Compare RLP data equality
* [toRaw](./utilities) - Convert to raw array

### Type Guards

* [isData](./utilities) - Check if value is RLP data
* [isBytesData](./utilities) - Check if value is bytes data
* [isListData](./utilities) - Check if value is list data
* [isList](./utilities) - Check if value is RLP list
* [isString](./utilities) - Check if value is RLP string

### Serialization

* [toJSON](./serialization) - Convert to JSON-serializable format
* [fromJSON](./serialization) - Convert from JSON format

## Types

> [tab] BrandedRlp
>
> ```typescript theme={null}
> export type BrandedRlp =
>   | { type: "bytes"; value: Uint8Array }
>   | { type: "list"; value: BrandedRlp[] };
> ```
>
> Main branded type. Union of bytes data (leaf nodes) and list data (nested arrays).
>
> **BytesData:** Leaf node containing raw bytes
>
> ```typescript theme={null}
> { type: "bytes", value: Uint8Array }
> ```
>
> **ListData:** Nested array of RLP data
>
> ```typescript theme={null}
> { type: "list", value: BrandedRlp[] }
> ```

> [tab] Encodable
>
> ```typescript theme={null}
> type Encodable =
>   | Uint8Array
>   | BrandedRlp
>   | Array<Uint8Array | BrandedRlp | any>;
> ```
>
> Input type for encoding methods. Accepts raw bytes, RLP data structures, or nested arrays.
>
> See [encode](https://voltaire.tevm.sh/primitives/rlp/encode.md) for details.

> [tab] Decoded
>
> ```typescript theme={null}
> type Decoded = {
>   data: BrandedRlp;
>   remainder: Uint8Array;
> };
> ```
>
> Return type for decode operations. Contains decoded RLP data and any remaining bytes (for stream decoding).

## Related

* [Rlp (Effect)](https://voltaire-effect.tevm.sh/primitives/rlp) - Effect.ts integration with Schema validation
* [Fundamentals](https://voltaire.tevm.sh/primitives/rlp/fundamentals.md) - Learn RLP encoding and decoding
* [Transaction](https://voltaire.tevm.sh/primitives/transaction.md) - Uses RLP for serialization
* [Keccak256](https://voltaire.tevm.sh/crypto/keccak256.md) - Keccak256 hashing for RLP data
* [Hex](https://voltaire.tevm.sh/primitives/hex.md) - Hex string encoding

## Specification

* [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf) - Formal RLP specification (Appendix B)
* [Ethereum Wiki - RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) - RLP encoding guide
* [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) - Typed transaction envelope using RLP


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