[Blockchain Substrate Tutorials] Install Substrate and run Substrate node on macOS

Install Substrate and run Substrate node on macOS

Substrate is an open source, modular, and extensible framework for building blockchains.

Substrate has been designed from the ground up to be flexible and allow innovators to design and build a blockchain network that meets their needs. It provides all the core components you need to build a customized blockchain node.

This page will guide you through the 2 steps needed to prepare a macOS for Substrate development.

Build Dependencies

Substrate development is easiest on Unix-based operating systems like macOS or Linux. The examples in the Substrate Tutorials and Recipes use Unix-style terminals to demonstrate how to interact with Substrate from the command line.

macOS

Open the Terminal application and execute the following commands:

1
2
3
4
5
6
7
# Install Homebrew if necessary https://brew.sh/
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# Make sure Homebrew is up-to-date, install openssl
$ brew update

$ brew install openssl

See https://substrate.dev/docs/en/knowledgebase/getting-started/#1-build-dependencies to learn more about Ubuntu/Debian, Arch Linux, Fedora, OpenSUSE and Windows.

Compiling the Node Template

Since Substrate is built with the Rust programming language, the first thing you will need to do is prepare the computer for Rust development - these steps will vary based on the computer’s operating system. Once Rust is configured, you will use its toolchains to interact with Rust projects; the commands for Rust’s toolchains will be the same for all supported, Unix-based operating systems.

For most users you can run our script to automate the steps listed below:

1
$ curl https://getsubstrate.io -sSf | bash -s -- --fast

Once Rust are installed, you can use Git to clone the Substrate Developer Hub Node Template, which serves as a good starting point for building on Substrate.

Clone the Node Template (version v3.0.0).

1
$ git clone -b v3.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template

Compile the Node Template

1
2
3
4
5
$ cd substrate-node-template
# NOTE: you should always use the `--release` flag

$ cargo build --release
# ^^ this will take a while!

Install the Front-End Template

This tutorial uses a ReactJS front-end template to allow you to interact with the Substrate-based blockchain node that you should have started compiling in the previous step. You can use this same front-end template to create UIs for your own projects in the future.

To use the front-end template, you need Yarn, which itself requires Node.js. If you don’t have these tools, you must install them from these instructions:

Now you can proceed to set up the front-end template with these commands.

1
2
3
4
5
6
7
# Clone the frontend template from github
$ git clone -b v3.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-front-end-template

# Install the dependencies
$ cd substrate-front-end-template

$ yarn install

Interacting with Your Node

Now that your node has finished compiling, let’s show you how everything works out of the box.

Starting Your Node

Run the following command to start your node:

1
2
# Run a temporary node in development mode
$ ./target/release/node-template --dev --tmp

Note the flags:

  • –dev this sets up a developer node chain specification

  • –tmp this saves all active data for the node (keys, blockchain database, networking info, …) and is deleted as soon as you properly terminate your node (using ctrl+c). So every time you start with this command, you will have a clean state to work from. If the node is killed, /tmp is cleaned automatically on the restart of your computer for linux based OSs, and these files can manually be removed if needed.

With this command, you should see something like this if your node is running successfully:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
2021-03-16 10:56:51  Running in --dev mode, RPC CORS has been disabled.
2021-03-16 10:56:51 Substrate Node
2021-03-16 10:56:51 ✌️ version 3.0.0-8370ddd-x86_64-linux-gnu
2021-03-16 10:56:51 ❤️ by Substrate DevHub <https://github.com/substrate-developer-hub>, 2017-2021
2021-03-16 10:56:51 📋 Chain specification: Development
2021-03-16 10:56:51 🏷 Node name: few-size-5380
2021-03-16 10:56:51 👤 Role: AUTHORITY
2021-03-16 10:56:51 💾 Database: RocksDb at /tmp/substrateP1jD7H/chains/dev/db
2021-03-16 10:56:51 ⛓ Native runtime: node-template-100 (node-template-1.tx1.au1)
2021-03-16 10:56:51 🔨 Initializing Genesis block/state (state: 0x17df…04a0, header-hash: 0xc43b…ed16)
2021-03-16 10:56:51 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
2021-03-16 10:56:51 ⏱ Loaded block-time = 6000 milliseconds from genesis on first-launch
2021-03-16 10:56:51 Using default protocol ID "sup" because none is configured in the chain specs
2021-03-16 10:56:51 🏷 Local node identity is: 12D3KooWQdU84EJCqDr4aqfhb7dxXU2fzd6i2Rn1XdNtsiM5jvEC
2021-03-16 10:56:51 📦 Highest known block at #0
2021-03-16 10:56:51 〽️ Prometheus server started at 127.0.0.1:9615
2021-03-16 10:56:51 Listening for new connections on 127.0.0.1:9944.
2021-03-16 10:56:54 🙌 Starting consensus session on top of parent 0xc43b4514877d7dcfff2459cdfe609a96cf8e9b9723589635d7215de6bf00ed16
2021-03-16 10:56:54 🎁 Prepared block for proposing at 1 [hash: 0x255bcf44df92dd4ccaca15d92d4a3db9d276e42843e21ab0cc840e207b2649d6; parent_hash: 0xc43b…ed16; extrinsics (1): [0x02bf…2cbd]]
2021-03-16 10:56:54 🔖 Pre-sealed block for proposal at 1. Hash now 0x9c14d9caccc37f8142fc348d184fb4bd8a8bc217a8979493d7f46d4220775616, previously 0x255bcf44df92dd4ccaca15d92d4a3db9d276e42843e21ab0cc840e207b2649d6.
2021-03-16 10:56:54 ✨ Imported #1 (0x9c14…5616)
2021-03-16 10:56:54 🙌 Starting consensus session on top of parent 0x9c14d9caccc37f8142fc348d184fb4bd8a8bc217a8979493d7f46d4220775616
2021-03-16 10:56:54 🎁 Prepared block for proposing at 2 [hash: 0x6cd4bd9d2a531750c10610bdaa5af0075745b6612ffa3623c14d699250b4e732; parent_hash: 0x9c14…5616; extrinsics (1): [0x3cc8…b8d9]]
2021-03-16 10:56:54 🔖 Pre-sealed block for proposal at 2. Hash now 0x05bd3317b51d717163dfa8847369d7f697c6180868c29f02d0b7ff79c5bbde3f, previously 0x6cd4bd9d2a531750c10610bdaa5af0075745b6612ffa3623c14d699250b4e732.
2021-03-16 10:56:54 ✨ Imported #2 (0x05bd…de3f)
2021-03-16 10:56:56 💤 Idle (0 peers), best: #2 (0x05bd…de3f), finalized #0 (0xc43b…ed16), ⬇ 0 ⬆ 0
2021-03-16 10:57:00 🙌 Starting consensus session on top of parent 0x05bd3317b51d717163dfa8847369d7f697c6180868c29f02d0b7ff79c5bbde3f
2021-03-16 10:57:00 🎁 Prepared block for proposing at 3 [hash: 0xa6990964cf4f184edc08acd61c3c01ac8975abbba6d42f4eec3f9658097aec04; parent_hash: 0x05bd…de3f; extrinsics (1): [0xd6ed…86a5]]
2021-03-16 10:57:00 🔖 Pre-sealed block for proposal at 3. Hash now 0xbe07e322ca525e580a3703637db191c6df091b0242a411b88fa0c43ef0ac31f8, previously 0xa6990964cf4f184edc08acd61c3c01ac8975abbba6d42f4eec3f9658097aec04.
2021-03-16 10:57:00 ✨ Imported #3 (0xbe07…31f8)
2021-03-16 10:57:01 💤 Idle (0 peers), best: #3 (0xbe07…31f8), finalized #1 (0x9c14…5616), ⬇ 0 ⬆ 0

If the number after finalized: is increasing, your blockchain is producing new blocks and reaching consensus about the state they describe!

A few notes on the example output above:

  • 💾 Database: RocksDb at /tmp/substrateP1jD7H/chains/dev/db : where chain data is being written

  • 🏷 Local node identity is: 12D3KooWQdU84EJCqDr4aqfhb7dxXU2fzd6i2Rn1XdNtsiM5jvEC: the node ID needed if you intend to connect to other nodes directly (more in the private network tutorial)

Start the Front-End Template

To interact with your local node, we will use the Substrate Developer Hub Front-End Template, which is a collection of UI components that have been designed with common use cases in mind.

Be sure to use the correct version of the template for the version of substrate you are using as major versions are not expected to be interoperable!

You already installed the Front-End Template; let’s launch it by executing the following command in the root directory of the Front-End Template:

1
2
# Make sure to run this command in the root directory of the Front-End Template
$ yarn start

Interact

Once the Front-End Template is running and loaded in your browser at http://localhost:8000/, take a moment to explore its components. At the top, you will find lots of helpful information about the chain to which you’re connected as well as an account selector that will let you control the account you use to perform on-chain operations.

Substrate Front-End

References

[1] Installation · Substrate Developer Hub - https://substrate.dev/docs/en/knowledgebase/getting-started/

[2] Official Substrate Documentation for Blockchain Developers · Substrate Developer Hub - https://substrate.dev/

[3] substrate-developer-hub/substrate-node-template: A new FRAME-based Substrate node, ready for hacking. - https://github.com/substrate-developer-hub/substrate-node-template

[4] substrate-developer-hub/substrate-front-end-template: A Polkadot.js API + React based template for building Substrate Front Ends - https://github.com/substrate-developer-hub/substrate-front-end-template

[5] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/