Chain Spec Builder¶
Introduction¶
chain-spec-builder is a command-line utility from the Polkadot SDK that builds chain specification (chain spec) files for any runtime that implements the GenesisBuilder runtime API. A chain spec is the JSON file a node loads to learn a chain's name, identifier, properties, boot nodes, runtime code, and genesis state.
Because the tool reads the genesis presets that the runtime itself exposes, it works with a compiled runtime Wasm blob and does not need a node binary that embeds the runtime. This makes it the usual companion to the Polkadot Omni Node, which starts a parachain node from a chain spec file.
This page covers installing chain-spec-builder, its subcommands and flags, and producing plain and raw chain specs for a runtime built from the parachain template. The commands and flags are taken from the tool's CLI source and README at the polkadot-stable2609-1 release. The crate documentation on docs.rs has the same reference in rustdoc form.
Install Chain Spec Builder¶
Download the pre-built chain-spec-builder binary from the Polkadot SDK release:
Alternatively, install it from source with cargo. The binary is published on crates.io as staging-chain-spec-builder because of a name conflict, and the installed command is still chain-spec-builder:
Note
The Set Up the Parachain Template tutorial pins chain-spec-builder to version 16.0.0, the version that matches the template's Polkadot SDK dependencies. The subcommands and flags on this page are the same in that version.
To confirm the installation, run:
The polkadot-omni-node binary also bundles the same tool as a subcommand, so polkadot-omni-node chain-spec-builder accepts the same subcommands and flags as the standalone binary.
Command Structure¶
Every invocation takes the following form:
The only top-level option is -c (--chain-spec-path), the path where commands that produce a chain spec write their output. It defaults to ./chain_spec.json. Because it belongs to the top-level command, place it before the subcommand name.
The tool provides the following subcommands:
| Subcommand | Description |
|---|---|
create | Creates a new chain spec by calling the genesis builder API of the provided runtime Wasm blob. |
list-presets | Prints the names of the genesis config presets the runtime provides. |
display-preset | Prints a genesis config preset. Without --preset-name, prints the default preset. |
verify | Checks that a chain spec can be converted to raw format, which surfaces uninitialized or invalid genesis config fields. |
convert-to-raw | Converts a plain chain spec into raw format. |
update-code | Replaces the runtime code stored in a chain spec. Supports plain and raw chain specs. |
add-code-substitute | Adds an entry to the chain spec's codeSubstitute object so that nodes use the given runtime code from a given block height. |
Commands that produce a chain spec (create, convert-to-raw, update-code, and add-code-substitute) never modify their input file in place. They write the result to the -c path.
Create a Chain Spec¶
The create subcommand builds a chain spec from a runtime Wasm blob. It takes the following options:
| Option | Default | Description |
|---|---|---|
-r, --runtime | Required | Path to the runtime Wasm blob. --runtime-wasm-path is accepted as an alias. |
-n, --chain-name | Custom | The chain name. |
-i, --chain-id | custom | The chain identifier. |
-t | live | The chain type: development, local, or live. This option has no long form. |
-c, --relay-chain | None | The relay chain the parachain connects to. Stored in the chain spec's relay_chain field. |
-p, --para-id | None | The parachain ID. Stored in the chain spec's para_id field. Requires --relay-chain. |
-s, --raw-storage | false | Export the chain spec in raw format. |
-v, --verify | false | Build the raw genesis storage silently to check the genesis config, then write the plain chain spec. |
--properties | tokenSymbol=UNIT,tokenDecimals=12 | Chain properties as comma-separated KEY=VALUE pairs. Can be passed more than once. |
The short form -c means --chain-spec-path before the subcommand and --relay-chain after create. Use the long forms if the distinction is unclear in a script.
After the options, create takes one of the following genesis actions, which decide where the genesis config comes from:
named-preset INSERT_PRESET_NAME: Uses a named genesis config preset that the runtime provides.patch INSERT_PATCH_PATH: Applies a JSON patch file on top of the runtime's default genesis config.full INSERT_CONFIG_PATH: Uses a JSON file that sets every genesis config field. No defaults are used.default: Uses the runtime's default genesis config. The default config may not be valid for every runtime; for example, it may lack session keys.
List the Runtime's Presets¶
Before creating a chain spec, list the presets your runtime provides. The following example uses the runtime built in Set Up the Parachain Template:
chain-spec-builder list-presets \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm
The command prints a JSON object with a presets array. The parachain template runtime defines the development and local_testnet presets in its genesis_config_presets.rs file.
To print the genesis config a preset produces, use display-preset:
chain-spec-builder display-preset \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
--preset-name development
Generate a Plain Chain Spec¶
A plain chain spec stores the genesis config as human-readable JSON, so you can review and edit it. The following command generates a development chain spec for the parachain template runtime. It is the same command the parachain tutorials in these docs use:
chain-spec-builder create -t development \
--relay-chain paseo \
--para-id 1000 \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
named-preset development
The command writes chain_spec.json in the current directory. The --relay-chain value records which relay chain the parachain is meant to connect to; set it to match the relay chain you run against. The --para-id value is stored for nodes to read when the runtime does not implement the GetParachainInfo runtime API. The parachain template implements that API, and its presets set the parachain ID to 1000.
To set chain properties such as the token symbol, add --properties:
chain-spec-builder create -t development \
--relay-chain paseo \
--para-id 1000 \
--properties tokenSymbol=UNIT,tokenDecimals=12,ss58Format=42 \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
named-preset development
Customize Genesis with a Patch¶
To change only some genesis values, write a patch file that contains the keys to override, and pass it to create patch. Keys you leave out keep their default values. The following patch, adapted from the example in the tool's README, sets the genesis balances of two accounts and the sudo key for the parachain template runtime:
{
"balances": {
"balances": [
["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", 1000000000000000],
["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", 1000000000000000]
]
},
"sudo": {
"key": "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty"
}
}
chain-spec-builder create -t development \
--relay-chain paseo \
--para-id 1000 \
--runtime ./target/release/wbuild/parachain-template-runtime/parachain_template_runtime.compact.compressed.wasm \
patch patch.json
The keys in a patch or full config file must match the runtime's genesis config. Run display-preset to see the structure your runtime expects.
Produce a Raw Chain Spec¶
A raw chain spec stores the genesis state as encoded storage keys and values instead of a JSON genesis config. Nodes on the same network must share the same raw genesis, so distribute the raw chain spec when other people run nodes for your chain.
You can produce a raw chain spec in either of the following ways:
-
Pass
-s(--raw-storage) tocreate: -
Convert an existing plain chain spec with
convert-to-raw:
Converting a plain chain spec lets you edit it first and then freeze the result. To check a plain chain spec without writing a raw one, run verify:
Update an Existing Chain Spec¶
The following subcommands modify the runtime code in a chain spec and write the result to the -c path. Both work with plain and raw chain specs.
-
Replace the runtime code with
update-code: -
Add a code substitute with
add-code-substitute, which takes the input chain spec, the runtime Wasm blob, and a block height:chain-spec-builder -c updated_chain_spec.json add-code-substitute chain_spec.json \ INSERT_RUNTIME_WASM_PATH INSERT_BLOCK_HEIGHTA code substitute tells nodes to use the given runtime code at the given block height. It is meant for recovering a chain that cannot produce blocks because of a runtime bug. For a parachain, the validation code registered on the relay chain must also be updated, or the relay chain rejects blocks built with the substituted runtime.
Use the Chain Spec¶
Start a node with the generated chain spec by passing it to the --chain flag of the Polkadot Omni Node:
To run the parachain with a local relay chain, reference the chain spec from a Zombienet network configuration, as shown in Run a Parachain Network. That guide also uses chain-spec-builder with the local_testnet preset to build the relay chain spec.
Where to Go Next¶
- Polkadot Omni Node: Run a parachain node from the chain spec you generated.
- Set Up the Parachain Template: Build the parachain template runtime and start it locally.
- Chain Spec Genesis reference: Read how genesis presets and the
GenesisBuilderAPI work in the Polkadot SDK.
| Created: November 17, 2026