Blockchain network constants library for Zig and TypeScript, auto-generated from DefiLlama/chainlist.
This repository provides a dual-language library that exposes blockchain chain constants generated from the DefiLlama chainlist submodule. The code generation script (scripts/generate.ts) parses the chainlist data and outputs type-safe constants for both Zig and TypeScript/JavaScript environments.
- π Auto-generated from the official DefiLlama chainlist
- π¦ Native Zig support with static type safety
- π¦ TypeScript/JavaScript support via Bun
- π Type-safe chain lookups by ID
- π 163+ blockchain networks with RPC endpoints, native currencies, and explorers
- π― Constant exports for every chain ID
# Clone with submodules
git clone --recursive <your-repo-url>
# Or if already cloned
git submodule update --init --recursive
# Install dependencies
bun installimport { allChains, getChainById, CHAIN_ID_FLR_14 } from "chains";
// Get all chains
console.log(`Total chains: ${allChains.length}`);
// Lookup by chain ID
const flare = getChainById(14);
console.log(flare?.name); // "Flare Mainnet"
console.log(flare?.nativeCurrency.symbol); // "FLR"
// Use constants
console.log(CHAIN_ID_FLR_14); // 14const std = @import("std");
const chains = @import("chains");
pub fn main() !void {
// Get all chains
std.debug.print("Total chains: {d}\n", .{chains.all_chains.len});
// Lookup by chain ID
if (chains.getChainById(14)) |chain| {
std.debug.print("Name: {s}\n", .{chain.name});
std.debug.print("Symbol: {s}\n", .{chain.native_currency.symbol});
}
}In your build.zig.zon:
.{
.name = "your-project",
.version = "0.1.0",
.dependencies = .{
.chains = .{
.url = "https://github.com/yourusername/chains/archive/<commit-hash>.tar.gz",
.hash = "...",
},
},
}In your build.zig:
const chains_dep = b.dependency("chains", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("chains", chains_dep.module("chains"));chains/
βββ src/
β βββ chains.ts # Generated TypeScript constants
β βββ chains.zig # Generated Zig constants
β βββ root.zig # Zig module entry point
β βββ main.zig # Zig example executable
βββ scripts/
β βββ generate.ts # Code generation script
βββ lib/
β βββ chainlist/ # Git submodule (DefiLlama/chainlist)
βββ build.zig # Zig build configuration
The generation process reads from lib/chainlist/constants/additionalChainRegistry/ and produces type-safe constants for both languages.
Update the chainlist submodule and regenerate:
# Update chainlist data
git submodule update --remote lib/chainlist
# Regenerate constants
bun run generateThis will:
- Parse all
chainid-*.jsfiles from the chainlist submodule - Generate
src/chains.zigwith Zig constants and structs - Generate
src/chains.tswith TypeScript constants and interfaces
# TypeScript
bun run build
# Zig
zig build
# Run example
zig build run# Zig tests
zig build testEach chain includes:
- name: Full chain name
- chain: Short identifier
- chainId / chain_id: EIP-155 chain ID
- networkId / network_id: Network ID
- shortName / short_name: Short name
- rpc: Array of RPC endpoints (HTTP/HTTPS URLs)
- nativeCurrency / native_currency: Native currency details (name, symbol, decimals)
- infoURL / info_url: Chain information URL (optional)
- explorers: Block explorer URLs with names (optional)
For each chain, the following constants are generated:
TypeScript:
CHAIN_ID_<NAME>: Chain ID constant (e.g.,CHAIN_ID_FLR_14)<name>: Chain object with all dataallChains: Array of all chainschainById: Record mapping chain IDs to chain objectsgetChainById(chainId): Lookup function
Zig:
CHAIN_ID_<NAME>: Chain ID constant (e.g.,CHAIN_ID_FLR_14)<name>: Chain struct with all data<name>_rpcs: RPC endpoints array<name>_explorers: Explorers array (if available)all_chains: Array of all chainsgetChainById(chain_id): Lookup function
Chain data sourced from DefiLlama/chainlist.