Try it Live
Run RLP examples in the interactive playground
RLP Types
RLP data type system defining bytes data, list data, and type guards for working with RLP structures.Overview
RLP uses a discriminated union type to represent two kinds of data:- BytesData - Leaf nodes containing raw bytes
- ListData - Nested arrays of RLP data
BrandedRlp
Core type representing RLP data structures.type field distinguishes between bytes and list variants.
Properties:
type: "bytes" | "list"- Discriminant fieldvalue: Uint8Array | BrandedRlp[]- Data payload
BytesData Variant
Represents a leaf node with raw bytes:ListData Variant
Represents a nested array of RLP data:Type Guards
Runtime type checking functions that narrow TypeScript types.isData
Checks if value is any RLP data structure.Implementation
Checks for required structure:- Value is object (not null)
- Has
typefield - Has
valuefield - Type is either “bytes” or “list”
isBytesData
Checks if value is bytes data specifically.Implementation
UsesisData then checks type field:
isListData
Checks if value is list data specifically.Implementation
UsesisData then checks type field:
Type Patterns
Discriminated Union Pattern
RLP uses TypeScript discriminated unions for type safety:Type Narrowing with Guards
Combine type guards with TypeScript narrowing:Exhaustive Type Checking
Ensure all type variants are handled:Working with Types
Creating RLP Data
UseRlp() constructor for automatic type detection:
Manual Construction
Create structures directly:Type-safe Access
Use type guards for safe access:Type Validation
Runtime Validation
Type guards perform runtime validation:Type Assertions
Assert types when you know the structure:Related Types
Encodable
Input type for encoding operations:Decoded
Output type from decoding operations:Type Examples
Transaction Type
Merkle Proof Type
Related
- Encoding - Encode typed data to RLP
- Decoding - Decode RLP to typed structures
- Utilities - Helper functions for working with types
- Branded Types - Type branding pattern

