Skip to main content
This example walks through transforming Frames into the Batch types.
Steps and handling of types with respect to chain tip, ordering of frames, re-orgs, and more are not covered by this example. This example solely demonstrates the most trivial way to transform individual Frames into a Batch type.

Walkthrough

The high level transformation is the following.
Given the raw, batch-submitted frame data as bytes (read in with the hex! macro), the first step is to decode the frame data into Frames using Frame::decode. Once all the Frames are decoded, the Channel can be constructed using the ChannelId of the first frame.
Frames may also be added to a Channel once decoded with the Channel::add_frame method.
When the Channel is Channel::is_ready(), the frame data can taken from the Channel using Channel::frame_data(). This data is represented as Bytes and needs to be decompressed using the respective compression algorithm depending on which hardforks are activated (using the RollupConfig). For the sake of this example, brotli is used (which was activated in the Fjord hardfork). Decompressed brotli bytes can then be passed right into Batch::decode to wind up with the example’s desired Batch.

Running this example

  • Clone the examples repository: git clone git@github.com:ethereum-optimism/optimism.git
  • Run: cargo run --example frames_to_batch