> ## 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 title="Try it Live" icon="play" href="https://playground.tevm.sh?example=primitives/rlp.ts">
  Run RLP examples in the interactive playground
</Card>

<Tip>
  New to RLP? Start with [Fundamentals](/primitives/rlp/fundamentals) for guided examples and encoding rules.
</Tip>

## Type Definition

[Branded](/getting-started/branded-types) 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](./encode) - 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](./encode) - Encode object to RLP structure
* [encodeVariadic](./encode) - Encode multiple arguments
* [encodeBatch](./encode) - Batch encode multiple items

### Decoding

* [decode](./decode) - Decode RLP bytes to data structures
* [decodeArray](./decode-array) - Decode RLP list to array
* [decodeObject](./decode) - Decode RLP to object
* [decodeBatch](./decode) - 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

<Tabs>
  <Tab title="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>

  <Tab title="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](./encode) for details.
  </Tab>

  <Tab title="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).
  </Tab>
</Tabs>

## Related

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