Substrate 安装 + 创建测试链 + 启动私有网络

  • 前言
  • 一、substrate 环境安装
    • 1.Build Dependencies
    • 2.Rust Developer Environment
  • 二、Create Your First Substrate Chain
    • 1.Compiling the Node Template
    • 2.安装 Front-End Template
    • 3.启动节点
  • 三、启动私有网络
    • 1.启动 Alice
    • 2.连接UI
    • 3.BOb 加入
    • 4.生成 Subkey 密钥
    • 5.创建自定义的 chain spec
    • 6.创建私有网络
    • 7.将密钥添加到密钥库
    • 8.其他参与者加入
  • BUG总结

前言

此文档用于 substrate 学习记录,官方文档链接在此。

一、substrate 环境安装

1.Build Dependencies

sudo apt update
# May prompt for location information
sudo apt install -y git clang curl libssl-dev

2.Rust Developer Environment

# Install
curl https://sh.rustup.rs -sSf | sh
# Configure
source ~/.cargo/env
rustup default stable
rustup update
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

一遍不行执行两遍!

二、Create Your First Substrate Chain

这是官方给出的一个创链过程,可以使用 Win10 子系统配合 Win10 浏览器使用。

1.Compiling the Node Template

git clone -b v3.0.0 --depth 1 https://github.com/substrate-developer-hub/substrate-node-template
cd substrate-node-template
# NOTE: you should always use the `--release` flag
cargo build --release
# ^^ this will take a while!

2.安装 Front-End Template

可以在 Win10 上进行,需要安装 nodejs 和 Yarn 后继续。

# 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

3.启动节点

# 在开发模式运行一个临时节点
./target/release/node-template --dev --tmp

三、启动私有网络

1.启动 Alice

# Purge any chain data from previous runs
# You will be prompted to type `y`
./target/release/node-template purge-chain --base-path /tmp/alice --chain local
# Start Alice's node
./target/release/node-template \--base-path /tmp/alice \--chain local \--alice \--port 30333 \--ws-port 9945 \--rpc-port 9933 \--node-key 0000000000000000000000000000000000000000000000000000000000000001 \--telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \--validator

2.连接UI

UI地址

3.BOb 加入

./target/release/node-template purge-chain --base-path /tmp/bob --chain local
./target/release/node-template \--base-path /tmp/bob \--chain local \--bob \--port 30334 \--ws-port 9946 \--rpc-port 9934 \--telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \--validator \--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp

flag 的更多细节,可以通过运行以下代码获取:

./target/release/node-template --help

4.生成 Subkey 密钥

Subkey 安装

sr25519:

# subkey command
subkey generate --scheme sr25519
# subkey output
Secret phrase `infant salmon buzz patrol maple subject turtle cute legend song vital leisure` is account:Secret seed:      0xa2b0200f9666b743402289ca4f7e79c9a4a52ce129365578521b0b75396bd242Public key (hex): 0x0a11c9bcc81f8bd314e80bc51cbfacf30eaeb57e863196a79cccdc8bf4750d21Account ID:       0x0a11c9bcc81f8bd314e80bc51cbfacf30eaeb57e863196a79cccdc8bf4750d21SS58 Address:     5CHucvTwrPg8L2tjneVoemApqXcUaEdUDsCEPyE7aDwrtR8D

ed25519:

# subkey command
subkey inspect --scheme ed25519 "infant salmon buzz patrol maple subject turtle cute legend song vital leisure"
# subkey output
Secret phrase `infant salmon buzz patrol maple subject turtle cute legend song vital leisure` is account:Secret seed:      0xa2b0200f9666b743402289ca4f7e79c9a4a52ce129365578521b0b75396bd242Public key (hex): 0x1a0e2bf1e0195a1f5396c5fd209a620a48fe90f6f336d89c89405a0183a857a3Account ID:       0x1a0e2bf1e0195a1f5396c5fd209a620a48fe90f6f336d89c89405a0183a857a3SS58 Address:     5CesK3uTmn4NGfD3oyGBd1jrp4EfRyYdtqL3ERe9SXv8jUHb

5.创建自定义的 chain spec

我们无需从头开始写新的 chain spec,可以对之前使用的 chain spec 进行一些修改。 首先,我们需要将 chain spec 导出到一个名为 customSpec.json 的文件中:

# Export the local chain spec to json
./target/release/node-template build-spec --disable-default-bootnode --chain local > customSpec.json

打开文件可以看到如下两个重要位置,Aura 为生产区块验证,Grandpa 为达成区块的最终确定性验证。

我们通过上面步骤生产出两份密钥,修改对应位置内容即可。

当 chain spec 准备好后,我们将其转换为 “原生” chain spec。 原生 chain spec 包含着所有相同的信息,但它同时也包含节点用于引用本地存储数据的已编码的存储密钥。 部署原生 chain spec 可以确保每个节点用适当的存储密钥对数据进行存储:

./target/release/node-template build-spec --chain=customSpec.json --raw --disable-default-bootnode > customSpecRaw.json

6.创建私有网络

# purge chain (only required for new/modified dev chain spec)
./target/release/node-template purge-chain --base-path /tmp/node01 --chain local -y
# start node01
./target/release/node-template \--base-path /tmp/node01 \--chain ./customSpecRaw.json \--port 30333 \--ws-port 9945 \--rpc-port 9933 \--telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \--validator \--rpc-methods Unsafe \--name MyNode01

7.将密钥添加到密钥库

在网络中的每一个节点添加密钥,包括了 Aura 和 GRANDPA 两个密钥,两个密钥的作用已经在上文提到。用浏览器打开 Polkadot-JS Apps 可以看到当前的节点信息,链接为:https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9945#/explorer。

找到 rpc calls 添加 aura 和 grandpa 密钥。

8.其他参与者加入

# purge chain (only required for new/modified dev chain spec)
./target/release/node-template purge-chain --base-path /tmp/node02 --chain local -y# start node02
./target/release/node-template \--base-path /tmp/node02 \--chain ./customSpecRaw.json \--port 30334 \--ws-port 9946 \--rpc-port 9934 \--telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \--validator \--rpc-methods Unsafe \--name MyNode02 \--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWAvdwXzjmRpkHpz8PzUTaX1o23SdpgAWVyTGMSQ68QXK6# you MUST fill the correct info in the line above:# --bootnodes /ip4/<IP Address>/tcp/<p2p Port>/p2p/<Peer ID>

同样需要导入 arua 和 grandpa 密钥,本地 APPS UI 上修改端口即可进入对应节点,加入密钥后重启开始产块。

BUG总结

  • substrate 安装 Rust – update crates.io过慢
    解决:在实际开发中,为了更快速下载第三方包,我们需要把crates.io换国内的镜像源,否则在拉取 crates.io 仓库代码会非常慢,Updating crates.io index 卡很久,很多次超时导致引用库没法编译,我们首先创建一个 config 文件放到 $HOME/.cargo/config 文件中,这里使用 vim 编辑器:vim config 加入代码:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"# 替换成你偏好的镜像源
replace-with = 'sjtu'
#replace-with = 'ustc'# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"
  • substrate 安装 报错 Blocking waiting for file lock on package cache
    解决:Cargo.lock被其他程序正在写入,独占了。一般关掉那个程序就行。原来是在cargo文件夹下面,.package_cache被加锁阻塞,所以进入对应的cargo文件夹下面,删除.package_cache文件即可。
  • Alice and bob test chain 报错:error: Found argument ‘tmp/bob’ which wasn’t expected, or isn’t valid in this context
    解决:官方文档代码错误,bob加入代码:
./target/release/node-template purge-chain --base-path / tmp/bob --chain local

可以发现 tmp 前多一个空格,删除即可。

  • 参与者进入时:The bootnode you want to connect to at … provided a different peer ID than the one you expect: …
    解决:
# you MUST fill the correct info in the line above:
# --bootnodes /ip4/<IP Address>/tcp/<p2p Port>/p2p/<Peer ID>

substrate 学习记录(一):Substrate 安装 + 创建测试链 + 启动私有网络相关推荐

  1. APPCAN学习笔记005---AppCan IDE安装下载,AppCan IDE启动

    APPCAN学习笔记005---AppCan IDE安装下载,AppCan IDE启动 创梦技术交流平台:资源下载,技术交流,网络赚钱: 交流qq群:1群:248318056 2群:251572072 ...

  2. 知识图谱、NLP学习记录(软件安装教程,知识学习等)

    pycharm库镜像网址 清华镜像 https://pypi.tuna.tsinghua.edu.cn/simple/ 阿里云镜像 http://mirrors.aliyun.com/pypi/sim ...

  3. gradle exclude_Gradle学习记录020 java工程的测试 part1

    详细学习如何用Gradle测试java工程.第二部分.该学习记录基于Gradle官方网站资料.本篇参考链接如下: https://docs.gradle.org/current/userguide/j ...

  4. DirectX 11 学习笔记(3)- 创建交换链

    填充DXGI_SWAP_CHAIN_DESC结构体来描述我们将要创建的交换链的特性. Typedef struct DXGI_SWAP_CHAIN_DESC {DXGI_MODE_DESC Buffe ...

  5. (转载)Linux 学习记录 一(安装、基本文件操作)

     Linux distributions主要分为两大系统,一种是RPM方式安装软件的系统,包括Red Hat,Fedora,SuSE等都是这类:一种则是使用Debian的dpkg方式安装软件的系统,包 ...

  6. Python学习,从入门安装到测试,一篇到位!

    本文以 Eric Matthes 的<Python编程:从入门到实践>为基础,以有一定其他语言经验的程序员视角,对书中内容提炼总结,化繁为简,将这本书的精髓融合成一篇10分钟能读完的文章. ...

  7. Rabbitmq学习笔记007---Centos7下安装rabbitmq_测试通过

    JAVA技术交流QQ群:170933152 1.在Centos下安装rabbitmq,之前都是在windows中安装的,centos下安装还挺麻烦 这里介绍两种安装方法: 第一种,我测试了,太慢了,不 ...

  8. php学习记录(phpstudy环境安装和phpstorm使用中的一些踩坑)

    注:以下内容已录制视频点击观看 1. phpstorm安装 IDE官网链接: https://www.jetbrains.com/phpstorm/ 下载后只能免费试用30天.可以网上下载破解版. 2 ...

  9. HTML+CSS学习记录01--VScode编辑器安装与配置

    https://www.cnblogs.com/csji/p/13558221.html 1.转为中文 ctrl+shift+p 找到configure display language,选择zh-c ...

  10. 【ESP32学习记录】ESP-IDF安装(Espressif-IDE)

    安装ESP-IDF同时安装Espressif IDE (Espressif IDE 是乐鑫基于 Eclipse CDT,专为乐鑫物联网开发框架 ESP-IDF 打造的独立集成开发环境) 下载ESP-I ...

最新文章

  1. no no no.不要使用kill -9.
  2. 一年月份大小月口诀_有关12个月份的顺口溜
  3. 余承东:华为 P50 系列无 5G 版本,但依然流畅
  4. ruby gem passenger依赖关系
  5. 计算机打开就是桌面界面的讲解,电脑桌面图标打不开,小猪教您电脑桌面图标打不开怎么办...
  6. linux怎么编译sharedptr,如何使用智能指针(例如auto_ptr r shared_ptr)在Linux上使用C++生成链接列表数据结构?...
  7. 服务器本地打开asp文件路径,服务器本地打开asp文件
  8. Ubuntu系统中创建虚拟环境
  9. java derby xsai2,java-j内的引用罐
  10. Python数据的精度
  11. 电机扭矩计算机公式由来T=9950*P/
  12. IDEA文件编码格式修改为UTF-8
  13. android 怎么判断手机号是移动还是联通
  14. Windows桌面应用程序(2-1-1st) 如何为桌面应用程序设计出色的用户体验
  15. 【附源码】计算机毕业设计JAVA网上鲜花店系统
  16. 微信公众号如何上传附件(Word、Excel、Pdf、PPT),三步轻松实现
  17. java计算机毕业设计高校体育器材及场地管理(附源码、数据库)
  18. 青少年python一级考试试题,青少年python一级考试
  19. 发展最快的小程序:甩甩宝宝
  20. java使用了未经检查或不安全的操作--的解决方法

热门文章

  1. 【3D制图软件●13.4.059中文破解版】一款强大的CAD软件
  2. 小程序和H5 之间的通信
  3. 修改IDEA格式化单行注释 后增加空格
  4. 需求分析中常用的图形工具
  5. 南山科技园的IDC机房怎么样?
  6. Kettle的改名由来
  7. Scratch(四):万圣节南瓜点灯
  8. windows无法完成格式化U盘与U盘修复对几种解决方法
  9. XPS文件转换成PDF
  10. 低代码平台对程序员产生的内卷,零代码、低代码系列之一「对于零代、低代码平台的思考」