[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 | Install Homebrew if necessary https://brew.sh/ |
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 | cd substrate-node-template |
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 | Clone the frontend template from github |
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 | Run a temporary node in development mode |
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 | 2021-03-16 10:56:51 Running in --dev mode, RPC CORS has been disabled. |
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 | Make sure to run this command in the root directory of the Front-End Template |
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.
References
[5] The Missing Package Manager for macOS (or Linux) — Homebrew - https://brew.sh/