polkadot_sdk_docs/reference_docs/cli.rs
1//! # Substrate CLI
2//!
3//! Let's see some examples of typical CLI arguments used when setting up and running a
4//! Substrate-based blockchain. We use the [`solochain-template`](https://github.com/paritytech/polkadot-sdk-solochain-template)
5//! on these examples.
6//!
7//! #### Checking the available CLI arguments
8//! ```bash
9//! ./target/debug/node-template --help
10//! ```
11//! - `--help`: Displays the available CLI arguments.
12//!
13//! #### Starting a Local Substrate Node in Development Mode
14//! ```bash
15//! ./target/release/node-template \
16//! --dev
17//! ```
18//! - `--dev`: Runs the node in development mode, using a pre-defined development chain
19//! specification.
20//! This mode ensures a fresh state by deleting existing data on restart.
21//!
22//! #### Generating Custom Chain Specification
23//! ```bash
24//! ./target/debug/node-template \
25//! build-spec \
26//! --disable-default-bootnode \
27//! --chain local \
28//! > customSpec.json
29//! ```
30//!
31//! - `build-spec`: A subcommand to generate a chain specification file.
32//! - `--disable-default-bootnode`: Disables the default bootnodes in the node template.
33//! - `--chain local`: Indicates the chain specification is for a local development chain.
34//! - `> customSpec.json`: Redirects the output into a customSpec.json file.
35//!
36//! #### Converting Chain Specification to Raw Format
37//! ```bash
38//! ./target/debug/node-template build-spec \
39//! --chain=customSpec.json \
40//! --raw \
41//! --disable-default-bootnode \
42//! > customSpecRaw.json
43//! ```
44//!
45//! - `--chain=customSpec.json`: Uses the custom chain specification as input.
46//! - `--disable-default-bootnode`: Disables the default bootnodes in the node template.
47//! - `--raw`: Converts the chain specification into a raw format with encoded storage keys.
48//! - `> customSpecRaw.json`: Outputs to `customSpecRaw.json`.
49//!
50//! #### Starting the First Node in a Private Network
51//! ```bash
52//! ./target/debug/node-template \
53//! --base-path /tmp/node01 \
54//! --chain ./customSpecRaw.json \
55//! --port 30333 \
56//! --ws-port 9945 \
57//! --rpc-port 9933 \
58//! --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
59//! --validator \
60//! --rpc-methods Unsafe \
61//! --name MyNode01
62//! ```
63//!
64//! - `--base-path`: Sets the directory for node data.
65//! - `--chain`: Specifies the chain specification file.
66//! - `--port`: TCP port for peer-to-peer communication.
67//! - `--ws-port`: WebSocket port for RPC.
68//! - `--rpc-port`: HTTP port for JSON-RPC.
69//! - `--telemetry-url`: Endpoint for sending telemetry data.
70//! - `--validator`: Indicates the node’s participation in block production.
71//! - `--rpc-methods Unsafe`: Allows potentially unsafe RPC methods.
72//! - `--name`: Sets a human-readable name for the node.
73//!
74//! #### Adding a Second Node to the Network
75//! ```bash
76//! ./target/release/node-template \
77//! --base-path /tmp/bob \
78//! --chain local \
79//! --bob \
80//! --port 30334 \
81//! --rpc-port 9946 \
82//! --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
83//! --validator \
84//! --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
85//! ```
86//!
87//! - `--base-path`: Sets the directory for node data.
88//! - `--chain`: Specifies the chain specification file.
89//! - `--bob`: Initializes the node with the session keys of the "Bob" account.
90//! - `--port`: TCP port for peer-to-peer communication.
91//! - `--rpc-port`: HTTP port for JSON-RPC.
92//! - `--telemetry-url`: Endpoint for sending telemetry data.
93//! - `--validator`: Indicates the node’s participation in block production.
94//! - `--bootnodes`: Specifies the address of the first node for peer discovery. Nodes should find
95//! each other using mDNS. This command needs to be used if they don't find each other.
96//!
97//! ---
98//!
99//! > If you are interested in learning how to extend the CLI with your custom arguments, you can
100//! > check out the [Customize your Substrate chain CLI](https://www.youtube.com/watch?v=IVifko1fqjw)
101//! > seminar.
102//! > Please note that the seminar is based on an older version of Substrate, and [Clap](https://docs.rs/clap/latest/clap/)
103//! > is now used instead of [StructOpt](https://docs.rs/structopt/latest/structopt/) for parsing
104//! > CLI arguments.