substrate基础(1)-substrate-node-template编译及部署

substrate-node-template
这个项目为substrate世界的入口,通过它来了解整个运转机制
该项目主要是为了方便开发人员调试和测试,以及初次接触substrate的入门者首选,掌握该项目后,再去接触正式项目,会容易很多

快速启动

  1. 这个项目是在rust的nightly版本下编译的,因此无论什么系统,一定要先安装好这个nightly版本环境(可以参考我早期文章Rust基础(1)-环境搭建及HelloWorld )。如果本地有多个rust版本环境,可以如下切换:
1
2
3
4
5
6
7
8
# 安装nightly
rustup toolchain install nightly

# 查看有哪些环境
rustup toolchain list

# 切换为nightly版
rustup default nightly
  1. 项目根目录下安装其余需要的依赖包:
1
2
3
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
cargo install https
  1. 项目根目录开始编译:
1
cargo b -r
  1. 验证是否安装完毕
1
./target/release/node-template --help
  1. 查看预定义帐户的帐户信息:alice
1
./target/release/node-template key inspect //alice
  1. 启动开发环境
1
2
3
4
./target/release/node-template --dev

# 稍微复杂点的启动,就是允许wss等对外通信
./target/release/node-template --dev --ws-external --rpc-external --no-telemetry --rpc-cors all
  1. 使用polkadot apps可视化
    1. 可以使用源码polkadot apps编译前端页面
    2. 可以使用官方已经编译并部署好的前端polkadot apps,其中将节点改为自己编译的substrate地址。部署会有坑,建议参考我的另一篇文章 substrate基础(2)-polkadot apps远端访问配置
    3. 目前具体页面操作请自行琢磨,后续我有可能会详细介绍
  2. 使用substrate-front-end-template可视化
    1. substrate-front-end-template 是官方提供的开发阶段的最简化页面,可以让开发人员很方便的可视化学习操作substrate,具体的编译和使用,请进去自行查看官方文档。很简单,这里就不解释了
    2. 简单整理下涉及到的命令:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 安装yarn
npm install -g yarn
# 下载源码
git clone https://github.com/substrate-developer-hub/substrate-front-end-template.git
# 安装依赖
cd substrate-front-end-template
yarn install
# 启动
yarn start
# 编译(可选)
yarn build
# 如果节点是远端服务器,请先前往项目位置:src/config/development.json 修改节点地址

# nginx的配置文件中,注意:user www www的配置,根据实际情况调整,否则访问不到
  1. 使用键盘ctrl + c停止节点

总结

本文编辑完毕

参考

[1] Substrate官方文档

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2017-2023 Jason
  • Visitors: | Views:

谢谢打赏~

微信