Try it Live
Run RLP examples in the interactive playground
Encodable Type
Encodable is a union type accepting any input that can be encoded to RLP:
Accepted Types
Uint8Array - Raw byte arrays (encoded as RLP strings):Usage Patterns
Transaction Encoding
Ethereum transactions use RLP encoding for signing and broadcasting:Block Encoding
Block headers are RLP-encoded lists:Custom Schema
Define typed structures with RLP encoding:Encoding Rules
RLP encoding uses the first byte (prefix) to indicate data type and length:Single Byte (0x00-0x7f)
Bytes with value < 0x80 encode as themselves:Short String (0-55 bytes)
For byte arrays 0-55 bytes, prefix with0x80 + length:
Long String (56+ bytes)
For byte arrays 56+ bytes, use long form:[0xb7 + length_of_length, ...length_bytes, ...bytes]
Short List (< 56 bytes total)
For lists with total payload < 56 bytes, prefix with0xc0 + total_length:
Long List (56+ bytes total)
For lists with total payload >= 56 bytes, use long form:[0xf7 + length_of_length, ...length_bytes, ...encoded_items]
Algorithm
Theencode method dispatches to specialized encoders:
- Uint8Array → Uses byte string encoding
- BrandedRlp (bytes) → Encodes as byte string
- BrandedRlp (list) → Encodes as list
- Array → Recursively encodes each element as list
Performance
Pre-sizing Buffers
Calculate size before encoding for better performance:Tree-shaking
Use specific encoders when type is known:Caching
Cache encoded results when encoding the same data multiple times:See Also
- decode - Decode RLP-encoded bytes
- encodeBytes - Encode byte string
- encodeList - Encode list
- encodeArray - Encode with schema
- Algorithm - RLP specification
- WASM - High-performance WASM encoder

