Skip to main content
Encode a list of values using Recursive Length Prefix (RLP) encoding
import { Rlp } from '@tevm/voltaire/Rlp';

// Encode a simple list of strings
const list = ["dog", "cat", "bird"];
const encoded = Rlp.encode(list.map((s) => new TextEncoder().encode(s)));
const hexEncoded = Hex.fromBytes(encoded);

// Encode nested lists
const nestedList = [
	new TextEncoder().encode("hello"),
	[new TextEncoder().encode("world")],
];
const encodedNested = Rlp.encode(nestedList);
const hexNested = Hex.fromBytes(encodedNested);

// Encode empty list
const emptyList = Rlp.encode([]);
const hexEmpty = Hex.fromBytes(emptyList);
This is a fully executable example. View the complete source with test assertions at examples/rlp/rlp-encode-list.ts.