Preparation for the Substrate Workshop
Follow the instructions below to best prepare for the "Build your own blockchain" and "Adding new pallets to Node Template" webinars. All webinars - past and future - are listed on Crowdcast.
The hardest part of all this is configuring your computer for Rust and Substrate development. Don't let this discourage you, you only have to do it once!
Environment
You need the Rust language and runtime to develop with the Substrate framework, which is what we'll be using in the webinar.
If you're on OS X or Linux, all the prerequisites can be installed via:
curl https://getsubstrate.io -sSf | bash -s -- --fast
For Windows without WSL (Windows Subsystem for Linux), the instructions are detailed here. With WSL, just use the one-liner above (recommended!)
After installing, running cargo --version
should say 1.44.0
or higher.
Bruno@LAPTOP-LL043296 ~/repos
λ cargo --version
cargo 1.49.0 (626f0f40e 2019-12-03)
We'll also need NodeJS and Yarn. We recommend installing NodeJS via NVM (Windows version here). Yarn needs to be installed globally as version 1.x, not version 2.x.
Post-install, the following commands should work:
Bruno@LAPTOP-LL043296 ~/repos
λ node --version
v10.16.3
Bruno@LAPTOP-LL043296 ~/repos
λ yarn --version
1.22.0
Remember that you need to close and re-open your terminal / bash / powershell / command prompt for the new paths to load and the node
and yarn
commands to become globally available.
Initialization
First let's make sure our Rust is at the most recent version and that it's able to compile WASM code.
rustup update nightly
rustup update stable
rustup target add wasm32-unknown-unknown --toolchain nightly
Let's now clone substrate-node-template - a template for development with some basic functionality on which we can build application-specific blockchains.
git clone -b v2.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
Following that, let's compile our substrate node.
cd substrate-node-template/
git checkout -b my-first-substrate-chain
cargo clean
cardo build --release
Since this can take up to 40 minutes, let's move onto other areas.
Errors
Because we're using an unstable nightly version of Rust, the compilation sometimes fails. In those instances, it can be necessary to install an older, more stable version:
rustup uninstall nightly
rustup install nightly-2020-10-01
rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-01
The command cargo build --release
should work now.
Front-end template
Substrate-node-template has a rudimentary companion front-end for interacting with the chain. Let's clone it:
git clone -b v2.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-front-end-template
cd substrate-front-end-template
yarn install
Running the node and the UI
To launch our compiled Substrate node:
./target/release/node-template --dev
The --dev
flag is there so the chain starts with some unlocked rich accounts and so that it can make its own blocks. Omitting this makes it wait for another validator to join the network, and no blocks get produced. The node will be running on port 9944 by default, so localhost:9944
or 127.0.0.1:9944
. Having a node running like this will also let you connect to it from the official Polkadot Apps UI using the URL ws://127.0.0.1:9944
. Then let's run the UI from within the substrate-front-end-template
directory:
yarn start
You should be able to do rudimentary reads and writes (transaction sending and balance reading) with your blockchain now using the UI at localhost:8000
.
Comments