Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(book): Load Rollup Config Example #224

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- [System Config](./building/genesis/system-config.md)
- [Consensus](./building/consensus.md)
- [Examples](./examples/README.md)
- [Load a Rollup Config](./examples/load-a-rollup-config.md)
- [Contributing](./CONTRIBUTING.md)
- [Licensing](./LICENSE.md)
- [Glossary](./glossary.md)
2 changes: 1 addition & 1 deletion book/src/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Examples for working with `op-alloy-*` crates.

TODO: document `op-alloy` crate use and using it with re-exports.
- [Load a Rollup Config for a Chain ID](./load-a-rollup-config.md)
Empty file.
34 changes: 34 additions & 0 deletions book/src/examples/load-a-rollup-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Loading a Rollup Config from a Chain ID

In this section, the code examples demonstrate loading the
rollup config for the given L2 Chain ID.

Let's load the Rollup Config for OP Mainnet which hash chain id 10.

```rust
use op_alloy_genesis::{OP_MAINNET_CONFIG, rollup_config_from_chain_id};

// The chain id for OP Mainnet
let op_mainnet_id = 10;

// Load a rollup config from the chain id.
let op_mainnet_config = rollup_config_from_chain_id(op_mainnet_id).expect("infallible");

// The chain id should match the hardcoded chain id.
assert_eq!(OP_MAINNET_CONFIG, op_mainnet_config);
```

> ⚠️ Available Configs
>
> The `rollup_config_from_chain_id` method in `op-alloy-genesis` uses hardcoded
> rollup configs. But, there are only a few of these hardcoded rollup configs in
> `op-alloy-genesis`. This method and these configs are provided for `no_std`
> environments where dynamic filesystem loading at runtime is not supported
> in `no_std` environments.
>
> In a `std` environment, the [superchain][superchain] crate may be used which
> dynamically provides all rollup configs from the [superchain-registry][registry]
> for their respective chain ids.

[superchain]: https://crates.io/crates/superchain
[registry]: https://github.com/ethereum-optimism/superchain-registry
Loading