You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
[](https://docs.substrate.io/playground/)[](https://matrix.to/#/#substrate-technical:matrix.org)
3
+
A fresh [Substrate](https://substrate.io/) node, ready for hacking :rocket:
4
4
5
-
A fresh FRAME-based [Substrate](https://www.substrate.io/) node, ready for hacking :rocket:
5
+
A standalone version of this template is available for each release of Polkadot in the [Substrate Developer Hub Parachain Template](https://github.com/substrate-developer-hub/substrate-parachain-template/) repository.
6
+
The parachain template is generated directly at each Polkadot release branch form the [Node Template in Substreate](https://github.com/paritytech/substrate/tree/master/bin/node-template) upstream
6
7
7
-
## Getting Started
8
-
9
-
Follow the steps below to get started with the Node Template, or get it up and running right from
10
-
your browser in just a few clicks using
11
-
the [Substrate Playground](https://docs.substrate.io/playground/):hammer_and_wrench:
12
-
13
-
### Using Nix
14
-
15
-
Install [nix](https://nixos.org/) and optionally [direnv](https://github.com/direnv/direnv) and
16
-
[lorri](https://github.com/nix-community/lorri) for a fully plug and play experience for setting up
17
-
the development environment. To get all the correct dependencies activate direnv `direnv allow` and
18
-
lorri `lorri shell`.
19
-
20
-
### Rust Setup
8
+
It is usually best to to use the stand-alone version to start a new project.
9
+
All bugs, suggestions, and feature requests should be made upstream in the [Substrate](https://github.com/paritytech/substrate/tree/master/bin/node-template) repository.
21
10
22
-
First, complete the [basic Rust setup instructions](./docs/rust-setup.md).
23
-
24
-
### Run
11
+
## Getting Started
25
12
26
-
Use Rust's native `cargo` command to build and launch the template node:
27
-
28
-
```sh
29
-
cargo run --release -- --dev
30
-
```
13
+
Depending on your operating system and Rust version, there might be additional packages required to compile this template.
14
+
Check the [Install](https://docs.substrate.io/install/) instructions for your platform for the most common dependencies.
15
+
Alternatively, you can use one of the [alternative installation](#alternatives-installations) options.
31
16
32
17
### Build
33
18
34
-
The `cargo run` command will perform an initial build. Use the following command to build the node
35
-
without launching it:
19
+
Use the following command to build the node without launching it:
36
20
37
21
```sh
38
22
cargo build --release
39
23
```
40
24
41
25
### Embedded Docs
42
26
43
-
Once the project has been built, the following command can be used to explore all parameters and
44
-
subcommands:
27
+
After you build the project, you can use the following command to explore its parameters and subcommands:
45
28
46
29
```sh
47
30
./target/release/node-template -h
48
31
```
49
32
50
-
## Run
33
+
You can generate and view the [Rust Docs](https://doc.rust-lang.org/cargo/commands/cargo-doc.html) for this template with this command:
51
34
52
-
The provided `cargo run` command will launch a temporary node and its state will be discarded after
53
-
you terminate the process. After the project has been built, there are other ways to launch the
54
-
node.
35
+
```sh
36
+
cargo +nightly doc --open
37
+
```
55
38
56
39
### Single-Node Development Chain
57
40
58
-
This command will start the single-node development chain with non-persistent state:
41
+
The following command starts a single-node development chain that doesn't persist state:
59
42
60
-
```bash
43
+
```sh
61
44
./target/release/node-template --dev
62
45
```
63
46
64
-
Purge the development chain's state:
47
+
To purge the development chain's state, run the following command:
65
48
66
-
```bash
49
+
```sh
67
50
./target/release/node-template purge-chain --dev
68
51
```
69
52
70
-
Start the development chain with detailed logging:
53
+
To start the development chain with detailed logging, run the following command:
> At the same time the following accounts will be pre-funded:
80
-
> - Alice
81
-
> - Bob
82
-
> - Alice//stash
83
-
> - Bob//stash
84
-
85
-
In case of being interested in maintaining the chain' state between runs a base path must be added
86
-
so the db can be stored in the provided folder instead of a temporal one. We could use this folder
87
-
to store different chain databases, as a different folder will be created per different chain that
88
-
is ran. The following commands shows how to use a newly created folder as our db base path.
89
-
90
-
```bash
59
+
Development chains:
60
+
61
+
- Maintain state in a `tmp` folder while the node is running.
62
+
- Use the **Alice** and **Bob** accounts as default validator authorities.
63
+
- Use the **Alice** account as the default `sudo` account.
64
+
- Are preconfigured with a genesis state (`/node/src/chain_spec.rs`) that includes several prefunded development accounts.
65
+
66
+
67
+
To persist chain state between runs, specify a base path by running a command similar to the following:
68
+
69
+
```sh
91
70
// Create a folder to use as the db base path
92
71
$ mkdir my-chain-state
93
72
@@ -103,23 +82,19 @@ $ ls ./my-chain-state/chains/dev
103
82
db keystore network
104
83
```
105
84
85
+
### Connect with Polkadot-JS Apps Front-End
106
86
107
-
### Connect with Polkadot-JS Apps Front-end
108
-
109
-
Once the node template is running locally, you can connect it with **Polkadot-JS Apps** front-end
110
-
to interact with your chain. [Click
111
-
here](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944) connecting the Apps to your
112
-
local node template.
87
+
After you start the node template locally, you can interact with it using the hosted version of the [Polkadot/Substrate Portal](https://polkadot.js.org/apps/#/explorer?rpc=ws://localhost:9944) front-end by connecting to the local node endpoint.
88
+
A hosted version is also available on [IPFS (redirect) here](https://dotapps.io/) or [IPNS (direct) here](ipns://dotapps.io/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer).
89
+
You can also find the source code and instructions for hosting your own instance on the [polkadot-js/apps](https://github.com/polkadot-js/apps) repository.
113
90
114
91
### Multi-Node Local Testnet
115
92
116
-
If you want to see the multi-node consensus algorithm in action, refer to our
117
-
[Simulate a network tutorial](https://docs.substrate.io/tutorials/get-started/simulate-network/).
93
+
If you want to see the multi-node consensus algorithm in action, see [Simulate a network](https://docs.substrate.io/tutorials/get-started/simulate-network/).
118
94
119
95
## Template Structure
120
96
121
-
A Substrate project such as this consists of a number of components that are spread across a few
122
-
directories.
97
+
A Substrate project such as this consists of a number of components that are spread across a few directories.
123
98
124
99
### Node
125
100
@@ -128,98 +103,74 @@ Substrate-based blockchain nodes expose a number of capabilities:
128
103
129
104
- Networking: Substrate nodes use the [`libp2p`](https://libp2p.io/) networking stack to allow the
130
105
nodes in the network to communicate with one another.
131
-
- Consensus: Blockchains must have a way to come to
132
-
[consensus](https://docs.substrate.io/main-docs/fundamentals/consensus/) on the state of the
133
-
network. Substrate makes it possible to supply custom consensus engines and also ships with
134
-
several consensus mechanisms that have been built on top of
135
-
[Web3 Foundation research](https://research.web3.foundation/en/latest/polkadot/NPoS/index.html).
106
+
- Consensus: Blockchains must have a way to come to [consensus](https://docs.substrate.io/fundamentals/consensus/) on the state of the network.
107
+
Substrate makes it possible to supply custom consensus engines and also ships with several consensus mechanisms that have been built on top of [Web3 Foundation research](https://research.web3.foundation/en/latest/polkadot/NPoS/index.html).
136
108
- RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes.
137
109
138
-
There are several files in the `node` directory - take special note of the following:
139
-
140
-
-[`chain_spec.rs`](./node/src/chain_spec.rs): A
141
-
[chain specification](https://docs.substrate.io/main-docs/build/chain-spec/) is a
142
-
source code file that defines a Substrate chain's initial (genesis) state. Chain specifications
143
-
are useful for development and testing, and critical when architecting the launch of a
144
-
production chain. Take note of the `development_config` and `testnet_genesis` functions, which
145
-
are used to define the genesis state for the local development chain configuration. These
and use them to configure the blockchain's initial state.
149
-
-[`service.rs`](./node/src/service.rs): This file defines the node implementation. Take note of
150
-
the libraries that this file imports and the names of the functions it invokes. In particular,
151
-
there are references to consensus-related topics, such as the
152
-
[block finalization and forks](https://docs.substrate.io/main-docs/fundamentals/consensus/#finalization-and-forks)
153
-
and other [consensus mechanisms](https://docs.substrate.io/main-docs/fundamentals/consensus/#default-consensus-models)
154
-
such as Aura for block authoring and GRANDPA for finality.
155
-
156
-
After the node has been [built](#build), refer to the embedded documentation to learn more about the
157
-
capabilities and configuration parameters that it exposes:
158
-
159
-
```shell
160
-
./target/release/node-template --help
161
-
```
110
+
There are several files in the `node` directory.
111
+
Take special note of the following:
112
+
113
+
-[`chain_spec.rs`](./node/src/chain_spec.rs): A [chain specification](https://docs.substrate.io/build/chain-spec/) is a source code file that defines a Substrate chain's initial (genesis) state.
114
+
Chain specifications are useful for development and testing, and critical when architecting the launch of a production chain.
115
+
Take note of the `development_config` and `testnet_genesis` functions,.
116
+
These functions are used to define the genesis state for the local development chain configuration.
117
+
These functions identify some [well-known accounts](https://docs.substrate.io/reference/command-line-tools/subkey/) and use them to configure the blockchain's initial state.
118
+
-[`service.rs`](./node/src/service.rs): This file defines the node implementation.
119
+
Take note of the libraries that this file imports and the names of the functions it invokes.
120
+
In particular, there are references to consensus-related topics, such as the [block finalization and forks](https://docs.substrate.io/fundamentals/consensus/#finalization-and-forks) and other [consensus mechanisms](https://docs.substrate.io/fundamentals/consensus/#default-consensus-models) such as Aura for block authoring and GRANDPA for finality.
121
+
122
+
162
123
163
124
### Runtime
164
125
165
-
In Substrate, the terms
166
-
"runtime" and "state transition function"
167
-
are analogous - they refer to the core logic of the blockchain that is responsible for validating
168
-
blocks and executing the state changes they define. The Substrate project in this repository uses
169
-
[FRAME](https://docs.substrate.io/main-docs/fundamentals/runtime-intro/#frame) to construct a
170
-
blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules
171
-
called "pallets". At the heart of FRAME is a helpful
172
-
[macro language](https://docs.substrate.io/reference/frame-macros/) that makes it easy to
173
-
create pallets and flexibly compose them to create blockchains that can address
174
-
[a variety of needs](https://substrate.io/ecosystem/projects/).
175
-
176
-
Review the [FRAME runtime implementation](./runtime/src/lib.rs) included in this template and note
177
-
the following:
178
-
179
-
- This file configures several pallets to include in the runtime. Each pallet configuration is
180
-
defined by a code block that begins with `impl $PALLET_NAME::Config for Runtime`.
181
-
- The pallets are composed into a single runtime by way of the
FRAME Support [system](https://docs.substrate.io/reference/frame-pallets/#system-pallets) library.
126
+
In Substrate, the terms "runtime" and "state transition function" are analogous.
127
+
Both terms refer to the core logic of the blockchain that is responsible for validating blocks and executing the state changes they define.
128
+
The Substrate project in this repository uses [FRAME](https://docs.substrate.io/fundamentals/runtime-development/#frame) to construct a blockchain runtime.
129
+
FRAME allows runtime developers to declare domain-specific logic in modules called "pallets".
130
+
At the heart of FRAME is a helpful [macro language](https://docs.substrate.io/reference/frame-macros/) that makes it easy to create pallets and flexibly compose them to create blockchains that can address [a variety of needs](https://substrate.io/ecosystem/projects/).
131
+
132
+
Review the [FRAME runtime implementation](./runtime/src/lib.rs) included in this template and note the following:
133
+
134
+
- This file configures several pallets to include in the runtime.
135
+
Each pallet configuration is defined by a code block that begins with `impl $PALLET_NAME::Config for Runtime`.
136
+
- The pallets are composed into a single runtime by way of the [`construct_runtime!`](https://crates.parity.io/frame_support/macro.construct_runtime.html) macro, which is part of the core FRAME Support [system](https://docs.substrate.io/reference/frame-pallets/#system-pallets) library.
185
137
186
138
### Pallets
187
139
188
-
The runtime in this project is constructed using many FRAME pallets that ship with the
189
-
[core Substrate repository](https://github.com/paritytech/substrate/tree/master/frame) and a
190
-
template pallet that is [defined in the `pallets`](./pallets/template/src/lib.rs) directory.
140
+
The runtime in this project is constructed using many FRAME pallets that ship with the [core Substrate repository](https://github.com/paritytech/substrate/tree/master/frame) and a template pallet that is [defined in the `pallets`](./pallets/template/src/lib.rs) directory.
191
141
192
142
A FRAME pallet is compromised of a number of blockchain primitives:
193
143
194
-
- Storage: FRAME defines a rich set of powerful
195
-
[storage abstractions](https://docs.substrate.io/main-docs/build/runtime-storage/) that makes
196
-
it easy to use Substrate's efficient key-value database to manage the evolving state of a
197
-
blockchain.
198
-
- Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched)
199
-
from outside of the runtime in order to update its state.
200
-
- Events: Substrate uses [events and errors](https://docs.substrate.io/main-docs/build/events-errors/)
201
-
to notify users of important changes in the runtime.
144
+
- Storage: FRAME defines a rich set of powerful [storage abstractions](https://docs.substrate.io/build/runtime-storage/) that makes it easy to use Substrate's efficient key-value database to manage the evolving state of a blockchain.
145
+
- Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched) from outside of the runtime in order to update its state.
146
+
- Events: Substrate uses [events and errors](https://docs.substrate.io/build/events-and-errors/) to notify users of important changes in the runtime.
202
147
- Errors: When a dispatchable fails, it returns an error.
203
-
- Config: The `Config` configuration interface is used to define the types and parameters upon
204
-
which a FRAME pallet depends.
148
+
- Config: The `Config` configuration interface is used to define the types and parameters upon which a FRAME pallet depends.
149
+
150
+
## Alternatives Installations
151
+
152
+
Instead of installing dependencies and building this source directly, consider the following alternatives.
205
153
206
-
### Run in Docker
154
+
### Nix
207
155
208
-
First, install [Docker](https://docs.docker.com/get-docker/) and
Install [nix](https://nixos.org/), and optionally [direnv](https://github.com/direnv/direnv) and [lorri](https://github.com/nix-community/lorri) for a fully plug-and-play experience for setting up the development environment.
157
+
To get all the correct dependencies, activate direnv `direnv allow` and lorri `lorri shell`.
158
+
159
+
### Docker
160
+
161
+
First, install [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/).
210
162
211
163
Then run the following command to start a single node development chain.
212
164
213
-
```bash
165
+
```sh
214
166
./scripts/docker_run.sh
215
167
```
216
168
217
-
This command will firstly compile your code, and then start a local development network. You can
0 commit comments