参考金晓文章 (Substrate入门,从一到五),致谢
一,搭建单节点链
- 搭建substrate基本运行环境
- 编译成功
- 单节点运行能够出块。
substrate的官方安装脚本掩盖了很多细节,在初次使用可以体验,但是以后安装建议直接安装,具体可以参考脚本https://getsubstrate.io/index.html,包括ubuntu安装的依赖包安装以及rust&cargo安装的环境变量等设置。具体步骤如下:
- 基本环境安装:Ubuntu 18.04.3 LTS
- 依赖安装apt install -y cmake pkg-config libssl-dev git gcc build-essential git clang libclang-dev
- 安装
rustcurl https://sh.rustup.rs -sSf | sh -s -- -y
source ~/.cargo/env
rustup default stable
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly - 下载并编译substrate
从git下载substate源码:
git clone https://github.com/paritytech/substrate
cd substrate
WASM_BUILD_TYPE=release cargo build - 运行单节点
cargo run --bin substrate -- --dev -d .sub --execution=NativeElseWasm
有以下输出:
Compiling node-runtime v2.0.0 (/home/chenggh/Substrate/substrate-20191224/bin/node/runtime)
Compiling node-rpc v2.0.0 (/home/chenggh/Substrate/substrate-20191224/bin/node/rpc)
Compiling node-executor v2.0.0 (/home/chenggh/Substrate/substrate-20191224/bin/node/executor)
Compiling node-cli v2.0.0 (/home/chenggh/Substrate/substrate-20191224/bin/node/cli)
Finished dev [unoptimized + debuginfo] target(s) in 17m 52s
Running `target/debug/substrate --dev -d .sub --execution=NativeElseWasm`
2019-12-24 19:09:30 Running in --dev mode, RPC CORS has been disabled.
2019-12-24 19:09:30 Substrate Node
2019-12-24 19:09:30 version 2.0.0-dd34fb435-x86_64-linux-gnu
2019-12-24 19:09:30 by Parity Technologies, 2017-2019
2019-12-24 19:09:30 Chain specification: Development
2019-12-24 19:09:30 Node name: ready-beam-8253
2019-12-24 19:09:30 Roles: AUTHORITY
2019-12-24 19:09:34 Initializing Genesis block/state (state: 0x3b7e…f4af, header-hash: 0xe792…7e99)
2019-12-24 19:09:34 Loading GRANDPA authority set from genesis on what appears to be first startup.
2019-12-24 19:09:49 Loaded block-time = BabeConfiguration { slot_duration: 3000, epoch_length: 200, c: (1, 4), genesis_authorities: [(Public(d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d (5GrwvaEF...)), 1)], randomness: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], secondary_slots: true } milliseconds from genesis on first-launch
2019-12-24 19:09:49 Creating empty BABE epoch changes on what appears to be first startup.
2019-12-24 19:09:54 Highest known block at #0
2019-12-24 19:09:54 Using default protocol ID "sup" because none is configured in the chain specs
2019-12-24 19:09:54 Local node identity is: QmbV2MPhrnCnTNGVc4MYpyazEafYCn4TC9wzPGMYS2XGMd
2019-12-24 19:09:54 Starting BABE Authorship worker
2019-12-24 19:09:54 Grafana data source server started at 127.0.0.1:9955
2019-12-24 19:10:13 Starting consensus session on top of parent 0xe792e2bd43df986a02f802749f77257cda36fa4fb903d98785d4f35eebab7e99
2019-12-24 19:10:13 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:18 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:23 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:28 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:34 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:40 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:44 Idle (0 peers), best: #0 (0xe792…7e99), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:10:44 Prepared block for proposing at 1 [hash: 0x5ee48736720f0be3e86d5b41618135be7d635992622b2f1814c8e86911dfed6f; parent_hash: 0xe792…7e99; extrinsics: [0x92d4…3b5b]]
2019-12-24 19:10:44 Pre-sealed block for proposal at 1. Hash now 0x04edb3a49ff2e2635b7594e55f00566ceee45f421c34f13eec94d6628e158809, previously 0x5ee48736720f0be3e86d5b41618135be7d635992622b2f1814c8e86911dfed6f.
2019-12-24 19:10:45 New epoch 0 launching at block 0x04ed…8809 (block slot 525747804 >= start slot 525747804).
2019-12-24 19:10:45 Next epoch starts at slot 525748004
2019-12-24 19:11:02 Imported #1 (0x04ed…8809)
2019-12-24 19:11:03 Polling the network future took 1.126763137s
2019-12-24 19:11:04 Starting consensus session on top of parent 0x04edb3a49ff2e2635b7594e55f00566ceee45f421c34f13eec94d6628e158809
2019-12-24 19:11:04 Idle (0 peers), best: #1 (0x04ed…8809), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:11:06 Failed to put hash 'Key(b"\x12 F \x87\x98\xc8\x0b\xe6S\x1cjdT1-\xb7\xd1PYb7k<\xca\x16\xcd\x18\xf9\x10\xd6\xfe\xa8^")' on Dht.
2019-12-24 19:11:09 Idle (0 peers), best: #1 (0x04ed…8809), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:11:14 Idle (0 peers), best: #1 (0x04ed…8809), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:11:19 Idle (0 peers), best: #1 (0x04ed…8809), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:11:24 Idle (0 peers), best: #1 (0x04ed…8809), finalized #0 (0xe792…7e99), ⬇ 0 ⬆ 0
2019-12-24 19:11:27 Prepared block for proposing at 2 [hash: 0x459887a3c8afe94bf6e2640fd754bd2dacabe2c78121dfefee329a9f17f3c1aa; parent_hash: 0x04ed…8809; extrinsics: [0x9285…a214]]
2019-12-24 19:11:27 Pre-sealed block for proposal at 2. Hash now 0xa0b01cd834e86f11e5d991b7837a31f7de9a9fde4fdfd5265d1ff8625adb6723, previously 0x459887a3c8afe94bf6e2640fd754bd2dacabe2c78121dfefee329a9f17f3c1aa.
2019-12-24 19:11:27 Imported #2 (0xa0b0…6723)
特别注意
Starting consensus # 共识准备
Pre-sealed block for proposing at <块高>, 区块hash, 父区块hash, 该区块中的交易hash # 预打包区块,其中的交易
Imported #<块高> # 区块落盘,一定要看到这一条才表示区块出块流程正常进行
二,测试单节点链
- 下载前端源码
git clone https://github.com/substrate-developer-hub/substrate-front-end-template.git - 安装yarn
安装 sudo apt install curl
添加GPG key
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
添加源
sudo sh -c 'echo "deb https://dl.yarnpkg.com/debian/ stable main" >> /etc/apt/sources.list.d/yarn.list'sudo apt update
sudo apt install yarn
3.编译运行
cd substrate-front-end-template
yarn build
yarn start