Typed access to EVM chain metadata generated from chainid.network/chains.json. The build script downloads the JSON on every build and turns it into a Chain enum with helpers for IDs, names, native currency, RPC URLs, and block times.
Add to your Cargo.toml:
chainlist-rs = "0.1"Use the enum:
use chainlist_rs::Chain;
fn main() {
let mainnet = Chain::Mainnet;
println!(
"{} (id {}) uses {}",
mainnet.name(),
mainnet.id(),
mainnet.native_currency().1
);
}Examples:
cargo run --example print_chaincargo run --example wallet_paramscargo run --example list_chains- Access full chain table:
let chains = chainlist_rs::all_chains();
chains.jsonis downloaded at build time from https://chainid.network/chains.json (network required).- Override with
CHAINS_JSON_URLto point to your mirror, orCHAINS_JSON_PATHif you want to supply a local file explicitly. - The downloaded file is kept in the build output dir and is ignored by git.
- Builds require network access to fetch
chains.jsonunless you provideCHAINS_JSON_PATH. - Quality gates:
cargo fmt,cargo clippy --all-targets --all-features,cargo test. - CI: PRs/pushes run fmt/clippy/tests with
CHAINS_JSON_PATH=data/chains.jsonto stay offline. - Publish check:
cargo package --dry-run(orcargo publish --dry-run) to verify the crate contents and metadata. - Automated release: pushing a tag
vX.Y.Zruns checks (fmt/clippy/tests) and publishes withcargo publish --lockedwhenCARGO_REGISTRY_TOKENis set in repo secrets; the tag must match the crate version. - Coverage: CI runs
cargo llvm-cov --lcovwithCHAINS_JSON_PATH=data/chains.jsonand uploads to Codecov (setCODECOV_TOKENif the repo is private).
MIT OR Apache-2.0 (dual license).