Start a Node
Started your first Substrate node from a template.
All of the Substrate tutorials and how-to guides require you to build and run a Substrate node in your development environment. To help you set up a working environment quickly, the Substrate Developer Hub maintains templates for you to use. For example, the substrate-node-template is a snapshot of the main Substrate node-template
binary that includes a core set of features to get you started.
After you start the node, you can connect to it using a web browser and a simple application that allows you to look up a balance for a predefined account.
Before you begin
Before you begin, verify the following:
You have an internet connection and access to an interactive shell terminal on your local computer.
You are generally familiar with software development and using command-line interfaces.
You have the Rust compiler and toolchain installed.
You can check whether you have Rust installed by running the
rustup show
command. If Rust is installed, this command displays version information for the toolchain and compiler. If Rust is not installed, the command doesn't return any output. For information about installing Rust, see Install.
Build the node template
Clone the node template repository by running the following command:
This command clones the
main
branch.Optionally, you can use the
--branch
command-line option and a tag to specify a version of Polkadot you want the node to be compatible with.Change to the root of the cloned directory:
Create a new branch to save your work by running a command similar to the following:
You can name the branch using any identifying information you choose. In most cases, you should include information about the year-month-day you cloned the branch in the name. For example:
Compile the node template:
The first time you compile the node, it can take some time to complete. When compiling is complete, you should see a line like this:
View information for the node
Verify that your node is ready to use and see information about the command-line options available by running the following command:
The usage information displays the command-line options you can use to:
start the node
work with accounts and keys
modify node operations
View account information for the predefined
Alice
development account by running the following command:The command displays the following account and address information:
Predefined development accounts like
Alice
andBob
are configured in a chain specification file. You'll learn more about node template files in Explore the code and more specifically about the chain specification file in Chain specification. For now, it's enough to be aware that development accounts exist to enable testing of simple transactions like balance transfers.
Start the blockchain
Start the node in development mode by running the following command:
In development mode, the chain doesn't require any peer computers to finalize blocks. As the node starts, the terminal displays output about the operations performed. If you see messages that blocks are being proposed and finalized, you have a running node.
Connect to the node
Now that your node is running, you can connect to it to check the balance of the predefined Alice
account. For this simple application, you can create one index.html
HTML file that uses JavaScript and the Polkadot-JS API to interact with the blockchain.
For example, this sample index.html demonstrates how to use JavaScript, the Polkadot-JS API, and HTML to do the following:
Take an account address as input.
Look up the account balance using an
onClick
event.Display the balance for the account as output.
To connect to the node and check an account balance:
Copy and paste the sample code for the Quick start: Get Balance application into a new file in your code editor and save the file on your local computer.
Open the
index.html
file in a web browser.Copy and paste the SS58 Address for the
Alice
account in the input field, then click Get Balance.
Stop the node
Go to the terminal that displays blockchain operations.
Stop the local blockchain and clear all state by pressing the
control-c
key combination.
Last updated