Skip to main content

Try it Live

Run Transaction examples in the interactive playground

Transaction Serialization

RLP encoding and decoding for all transaction types.

serialize

Serialize transaction to RLP-encoded bytes.

Parameters

  • tx: Any - Any transaction type (Legacy, EIP2930, EIP1559, EIP4844, EIP7702)

Returns

Uint8Array - RLP-encoded transaction bytes

Throws

  • Error("Unknown transaction type") - If transaction type is invalid
  • Error("Not implemented") - If type-specific serialization not implemented yet

Usage

Source: serialize.ts:11-26

deserialize

Deserialize RLP-encoded transaction bytes.

Parameters

  • data: Uint8Array - RLP-encoded transaction bytes

Returns

Transaction object (type depends on transaction type in data)

Throws

  • Error("Empty transaction data") - If data is empty
  • Error("Unknown transaction type") - If type byte is invalid
  • Error("Not implemented") - If type-specific deserialization not implemented yet
  • RLP decoding errors for malformed data

Usage

Source: deserialize.ts:12-28

Serialization Format

Legacy Transaction

Legacy transactions serialize directly as RLP list (no type prefix):
Example:

EIP-2930 Transaction (Type 1)

Format:
  • Type byte: 0x01
  • Followed by RLP-encoded list
  • Access list encoded as nested RLP structure

EIP-1559 Transaction (Type 2)

Format:
  • Type byte: 0x02
  • Followed by RLP-encoded list
  • Two gas fee fields instead of one

EIP-4844 Transaction (Type 3)

Format:
  • Type byte: 0x03
  • Followed by RLP-encoded list
  • Includes blob gas fee and blob hashes
  • Blob data NOT included in transaction (stored separately)

EIP-7702 Transaction (Type 4)

Format:
  • Type byte: 0x04
  • Followed by RLP-encoded list
  • Authorization list encoded as nested RLP structure

Type-Specific Serialization

Transaction.Legacy.serialize

Transaction.EIP1559.serialize

Transaction.EIP4844.serialize

Similar methods exist for EIP2930 and EIP7702. Source: serialize.ts

Round-Trip Serialization

Serialize and deserialize should be perfect inverses:

Access List Encoding

Access lists are RLP-encoded as nested structures:

Authorization List Encoding

Authorization lists for EIP-7702:

Network Transmission

Serialized transactions are used for:
  1. Gossip protocol - Broadcasting to peers
  2. Block inclusion - Stored in blocks
  3. Transaction pool - Mempool storage
  4. RPC responses - eth_getTransactionByHash

Storage Optimization

Serialized form is compact for storage:

Error Handling

Implementation Status

Transaction serialization implementation status: Many methods currently throw “Not implemented” - check test files for implementation status.

See Also

  • Hashing - Transaction and signing hash computation
  • Signing - Signature verification and sender recovery
  • detectType - Detect transaction type from bytes
  • RLP - Recursive Length Prefix encoding

EIP References