Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Substrate.io Migration] Tutorials -> Build a Blockchain -> Build a Local Blockchain #14

Merged
merged 16 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>cargo build --release</span>
<span data-ty>Compiling solochain-template-node</span>
<span data-ty>Finished `release` profile [optimized] target(s) in 27.12s</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div id='termynal' data-termynal>
<span data-ty='input'><span class='file-path'></span>./target/release/solochain-template-node --dev</span>
<br>
<span data-ty>2024-09-09 08:32:42 Substrate Node</span>
<span data-ty>2024-09-09 08:32:42 ✌️ version 0.1.0-8599efc46ae</span>
<span data-ty>2024-09-09 08:32:42 ❤️ by Parity Technologies <[email protected]>, 2017-2024</span>
<span data-ty>2024-09-09 08:32:42 📋 Chain specification: Development</span>
<span data-ty>2024-09-09 08:32:42 🏷 Node name: light-boundary-7850</span>
<span data-ty>2024-09-09 08:32:42 👤 Role: AUTHORITY</span>
<span data-ty>2024-09-09 08:32:42 💾 Database: RocksDb at /var/folders/x0/xl_kjddj3ql3bx7752yr09hc0000gn/T/substrate0QH9va/chains/dev/db/full</span>
<span data-ty>2024-09-09 08:32:42 🔨 Initializing Genesis block/state (state: 0xc2a0…16ba, header-hash: 0x0eef…935d)</span>
<span data-ty>2024-09-09 08:32:42 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.</span>
<span data-ty>2024-09-09 08:32:42 Using default protocol ID "sup" because none is configured in the chain specs</span>
<span data-ty>2024-09-09 08:32:42 🏷 Local node identity is: 12D3KooWPhdUzf66di1SuuRFgjkFs6X8jm3Uj2ss5ri31WuVAbgt</span>
<span data-ty>2024-09-09 08:32:42 Running libp2p network backend</span>
<span data-ty>2024-09-09 08:32:42 💻 Operating system: macos</span>
<span data-ty>2024-09-09 08:32:42 💻 CPU architecture: aarch64</span>
<span data-ty>2024-09-09 08:32:42 📦 Highest known block at #0</span>
<span data-ty>2024-09-09 08:32:42 〽️ Prometheus exporter started at 127.0.0.1:9615</span>
<span data-ty>2024-09-09 08:32:42 Running JSON-RPC server: addr=127.0.0.1:9944, allowed origins=["*"]</span>
<span data-ty>2024-09-09 08:32:47 💤 Idle (0 peers), best: #0 (0x0eef…935d), finalized #0 (0x0eef…935d), ⬇ 0 ⬆ 0</span>
<span data-ty>2024-09-09 08:32:48 🙌 Starting consensus session on top of parent 0x0eef4a08ef90cc04d01864514dc5cb2bd822314309b770b49b0177f920ed935d (#0)</span>
<span data-ty>2024-09-09 08:32:48 🎁 Prepared block for proposing at 1 (1 ms) [hash: 0xc14630b76907550bef9037dcbfafa2b25c8dc763495f30d9e36ad4b93b673b36; parent_hash: 0x0eef…935d; extrinsics (1): [0xbcd8…5132]</span>
<span data-ty>2024-09-09 08:32:48 🔖 Pre-sealed block for proposal at 1. Hash now 0xcb3d2f28bc73807dac5cf19fcfb2ac6d7e922756da9d41ca0c9dadbd0e45265b, previously 0xc14630b76907550bef9037dcbfafa2b25c8dc763495f30d9e36ad4b93b673b36.</span>
<span data-ty>2024-09-09 08:32:48 🏆 Imported #1 (0x0eef…935d → 0xcb3d…265b)</span>
<span data-ty>...</span>
</div>
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tutorials/.pages
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
title: Tutorials
nav:
- index.md
- 'Polkadot SDK': polkadot-sdk
4 changes: 4 additions & 0 deletions tutorials/polkadot-sdk/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title: Polkadot SDK
nav:
- index.md
- 'Build a Blockchain': build-a-blockchain
4 changes: 4 additions & 0 deletions tutorials/polkadot-sdk/build-a-blockchain/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title: Build a Blockchain
nav:
- index.md
- 'Build a Local Solochain': build-a-local-blockchain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: Build a Local Solochain
description: Learn to compile and launch a local blockchain node using Polkadot SDK. Build, run, and interact with a pre-configured node template.
---

# Build a Local Solochain

## Introduction

[Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank} offers a versatile and extensible blockchain development framework, enabling you to create custom blockchains tailored to your specific application or business requirements.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

This tutorial guides you through compiling and launching a standalone blockchain node using the [Polkadot SDK Solochain Template](https://github.com/paritytech/polkadot-sdk-solochain-template){target=\_blank}. You'll create a fully functional chain that operates independently, without connections to a relay chain or parachain.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

The node template provides a pre-configured, functional single-node blockchain you can run in your local development environment. It includes several key components, such as user accounts and account balances.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

These predefined elements allow you to experiment with common blockchain operations without requiring initial template modifications.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
In this tutorial, you will:

- Build and start a local blockchain node using the node template
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
- Explore how to use a front-end interface to:
- View information about blockchain activity
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
- Submit a transaction

By the end of this tutorial, you'll have a working local solochain and understand how to interact with it, setting the foundation for further customization and development.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

## Prerequisites

To get started with the node template, you'll need to have the following set up on your development machine first:

- Rust Installation - the node template is written in [Rust](https://www.rust-lang.org/){target=\_blank}, so you'll need to have it installed and configured on your system. Refer to the [Installation]() section for step-by-step instructions on setting up your development environment
eshaben marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

## Compile a Node

The [Polkadot SDK Solochain Template](https://github.com/paritytech/polkadot-sdk-solochain-template){target=\_blank} provides a ready-to-use development environment for building using the [Polkadot SDK](https://github.com/paritytech/polkadot-sdk){target=\_blank}. Follow these steps to compile the node:

1. Clone the node template repository:
```bash
git clone -b {{dependencies.polkadot_sdk_solochain_template.version}} {{dependencies.polkadot_sdk_solochain_template.repository_url}}
```

!!!note
This tutorial uses version `{{dependencies.polkadot_sdk_solochain_template.version}}` of the Polkadot SDK Solochain Template. Make sure you're using the correct version to match these instructions.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

2. Navigate to the root of the node template directory:
```bash
cd polkadot-sdk-solochain-template
```

3. Compile the node template:
```bash
cargo build --release
```

!!!note
Initial compilation may take several minutes, depending on your machine specifications. Always use the `--release` flag to build optimized, production-ready artifacts.

4. Upon successful compilation, you should see output similar to:
--8<-- 'code/tutorials/polkadot-sdk/build-a-blockchain/build-a-local-blockchain/compilation-output.html'
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

## Start the Local Node

After successfully compiling your node, you can run it and produce blocks. This process will start your local blockchain and allow you to interact. Follow these steps to launch your node in development mode:
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

1. In the terminal where you compiled your node, start it in development mode:
```bash
./target/release/solochain-template-node --dev
```
The `--dev` option does the following:
- Specifies that the node runs using the predefined development chain specification
- Deletes all active data (keys, blockchain database, networking information) when stopped
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
- Ensures a clean working state each time you restart the node

2. Verify that your node is running by reviewing the terminal output. You should see something similar to:
--8<-- 'code/tutorials/polkadot-sdk/build-a-blockchain/build-a-local-blockchain/node-output.html'
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

3. Confirm that your blockchain is producing new blocks by checking if the number after `finalized` is increasing
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
<div id='termynal' data-termynal>
<span data-ty>...</span>
<span data-ty>2024-09-09 08:32:47 💤 Idle (0 peers), best: #0 (0x0eef…935d), finalized #0 (0x0eef…935d), ⬇ 0 ⬆ 0</span>
<span data-ty>...</span>
<span data-ty>2024-09-09 08:32:52 💤 Idle (0 peers), best: #1 (0xcb3d…265b), finalized #0 (0x0eef…935d), ⬇ 0 ⬆ 0</span>
<span data-ty>...</span>
<span data-ty>2024-09-09 08:32:57 💤 Idle (0 peers), best: #2 (0x16d7…083f), finalized #0 (0x0eef…935d), ⬇ 0 ⬆ 0</span>
<span data-ty>...</span>
<span data-ty>2024-09-09 08:33:02 💤 Idle (0 peers), best: #3 (0xe6a4…2cc4), finalized #1 (0xcb3d…265b), ⬇ 0 ⬆ 0</span>
<span data-ty>...</span>
</div>

!!!note
The details of the log output will be explored in a later tutorial. For now, knowing that your node is running and producing blocks is sufficient.

## Interact with the Node

When running the template node, it's accessible by default at:

```bash
ws://localhost:9944
```
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
To interact with your node using the [Polkadot.js Apps](https://polkadot.js.org/apps/#/explorer){target=\_blank} interface, follow these steps:

1. Open [Polkadot.js Apps](https://polkadot.js.org/apps/#/explorer){target=\_blank} in your web browser and click the network icon in the top left corner
![](/images/tutorials/polkadot-sdk/build-a-blockchain/build-a-local-blockchain/build-a-local-blockchain-1.webp)

2. Connect to your local node:
1. Scroll to the bottom and select **Development**
2. Choose **Custom**
3. Enter `ws://localhost:9944` in the input field
4. Click the **Switch** button
![](/images/tutorials/polkadot-sdk/build-a-blockchain/build-a-local-blockchain/build-a-local-blockchain-2.webp)

3. Verify connection:
- Once connected, you should see **solochain-template-runtime** in the top left corner
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
- The interface will display information about your local blockchain
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
![](/images/tutorials/polkadot-sdk/build-a-blockchain/build-a-local-blockchain/build-a-local-blockchain-3.webp)

You are now connected to your local node and can now interact with it through the Polkadot.js Apps interface. This tool enables you to explore blocks, execute transactions, and interact with your blockchain's features. For in-depth guidance on using the interface effectively, refer to the [Polkadot.js Guides](https://wiki.polkadot.network/docs/learn-polkadot-js-guides){target=\_blank} available on the Polkadot Wiki.
0xLucca marked this conversation as resolved.
Show resolved Hide resolved
0xLucca marked this conversation as resolved.
Show resolved Hide resolved

<!-- TODO: Polkadot.js Apps guide -->

## Stop the Node

When you're done exploring your local node, you can stop it to remove any state changes you've made. Since you started the node with the `--dev` option, stopping the node will purge all persistent block data, allowing you to start fresh the next time.

To stop the local node:

1. Return to the terminal window where the node output is displayed
2. Press `Control-C` to stop the running process
3. Verify that your terminal returns to the prompt in the `polkadot-sdk-solochain-template` directory
7 changes: 7 additions & 0 deletions tutorials/polkadot-sdk/build-a-blockchain/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Build a Blockchain
description: Learn to build and manage Polkadot-SDK based blockchain nodes. Covers setup, networking, authorization, monitoring, and upgrades.
hide:
- feedback
template: subsection-index-page.html
---
7 changes: 7 additions & 0 deletions tutorials/polkadot-sdk/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Polkadot SDK
description: TODO
eshaben marked this conversation as resolved.
Show resolved Hide resolved
hide:
- feedback
template: subsection-index-page.html
---
5 changes: 4 additions & 1 deletion variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ dependencies:
architecture: macos-arm64
asset_transfer_api:
repository_url: https://github.com/paritytech/asset-transfer-api
version: 0.3.1
version: 0.3.1
polkadot_sdk_solochain_template:
repository_url: https://github.com/paritytech/polkadot-sdk-solochain-template
version: v0.0.2
Loading