|
1 |
| -# superchain |
2 |
| -Rust Bindings for the superchain-registry. |
| 1 | +# `superchain` |
| 2 | + |
| 3 | +Rust Bindings for the [superchain-registry][sr]. |
| 4 | + |
| 5 | +The best way to work with this repo is through the [`superchain`][sup] |
| 6 | +crate. [`superchain`][sup] is an optionally `no_std` crate that provides |
| 7 | +core types and bindings for the Superchain. |
| 8 | + |
| 9 | +It re-exports two crates: |
| 10 | +- [`superchain-primitives`][scp] |
| 11 | +- [`superchain-registry`][scr] _Only available if `serde` feature flag is enabled_ |
| 12 | + |
| 13 | +[`superchain-primitives`][scp] defines core types used in the `superchain-registry` |
| 14 | +along with a few default values for core chains. |
| 15 | + |
| 16 | +[`superchain-registry`][scr] provides bindings to all chains in the `superchain`. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Add the following to your `Cargo.toml`. |
| 21 | + |
| 22 | +```toml |
| 23 | +[dependencies] |
| 24 | +superchain = "0.2" |
| 25 | +``` |
| 26 | + |
| 27 | +To make make `superchain` `no_std`, toggle `default-features` off like so. |
| 28 | + |
| 29 | +```toml |
| 30 | +[dependencies] |
| 31 | +superchain = { version = "0.2", default-features = false } |
| 32 | +``` |
| 33 | + |
| 34 | +## Example |
| 35 | + |
| 36 | +[`superchain-registry`][scr] exposes lazily defined mappings from chain id |
| 37 | +to chain configurations that the [`superchain`][sup] re-exports. Below |
| 38 | +demonstrates getting the `RollupConfig` for OP Mainnet (Chain ID `10`). |
| 39 | + |
| 40 | +```rust |
| 41 | +use superchain::ROLLUP_CONFIGS; |
| 42 | + |
| 43 | +let op_chain_id = 10; |
| 44 | +let op_rollup_config = ROLLUP_CONFIGS.get(&op_chain_id); |
| 45 | +println!("OP Mainnet Rollup Config: {:?}", op_rollup_config); |
| 46 | +``` |
| 47 | + |
| 48 | +A mapping from chain id to `ChainConfig` is also available. |
| 49 | + |
| 50 | +```rust |
| 51 | +use superchain::OPCHAINS; |
| 52 | + |
| 53 | +let op_chain_id = 10; |
| 54 | +let op_chain_config = OPCHAINS.get(&op_chain_id); |
| 55 | +println!("OP Mainnet Chain Config: {:?}", op_chain_config); |
| 56 | +``` |
| 57 | + |
| 58 | +## Feature Flags |
| 59 | + |
| 60 | +- `serde`: Enables [`serde`][s] support for types and makes [`superchain-registry`][scr] types available. |
| 61 | +- `std`: Uses the standard library to pull in environment variables. |
| 62 | + |
| 63 | +<!-- Hyperlinks --> |
| 64 | + |
| 65 | +[sp]: ./crates/superchain-primitives |
| 66 | + |
| 67 | +[s]: https://crates.io/crates/serde |
| 68 | +[sr]: https://github.com/ethereum-optimism/superchain-registry |
| 69 | +[scr]: https://crates.io/crates/superchain-registry |
| 70 | +[sup]: https://crates.io/crates/superchain |
| 71 | +[scp]: https://crates.io/crates/superchain-primitives |
| 72 | +[superchain]: https://github.com/anton-rs/superchain |
| 73 | + |
0 commit comments