选对工具,搭建在 Substrate 诞生之前,想搭建一条自己的定制化私有

从技术的自由度讲,“ Substrate Core ”最大,你完全可以采用另一种语言来开发,只需要它能支持 WebAssembly 就好,前题是你要遵循 Substrate 的设计规范和相关协议。类似于只需要符合 PG 的网络接口标准,你可以用任何语言来编写 PG 的客户端一样。

从开发的简单程度来讲,“ Substrate Node ”最简单,只需稍作配置,你就可以立刻启动一个 Substrate 节点。

“ Substrate SRML ”则处于中间位置,既给你提供了一定的技术自由度,同时也没有那么难。一般情况下这都涉及到编写一定的 Rust 代码,有点类似你用 Spring Boot 开发时的情形。同时,采用这种方式你可以自行剪裁需要的模块,搭建自己钟意的“链条”。

作为迈向 Substrate 的第一步,本文不打算讲太多关于 Substrate 太多的概念,更多地关注于环境的搭建和最基本的示例。至于其他(比如涉及到的 rust 语言、概念、模板工程组成、合约等内容),则会留到后续文章再谈。

就搭建一个 Substrate 节点而言,其实过程并不复杂,总结起来有以下几步:

  • 搭建 rust 环境(关于 rust 的基础知识可以参见我的这个 PPT)
  • clone node-template
  • 修改、编译、测试、运行
  • 访问:https://polkadot.js.org/apps/#/settings?rpc=ws://127.0.0.1:9944 ,即可看到区块的情况

这些内容参考下面的文档就能轻易地完成:

  • Getting Started
  • Creating Your First Substrate Chain
  • Build a PoE Decentralized Application
  • Start a Private Network

即使不太明白其中的代码含义也没有关系,只需按其步骤进行即可。

对于 Mac 用户需要注意一下,因为直接按照文章所说的运行:

curl https://getsubstrate.io -sSf | bash -s -- --fast

你会得到以下错误:

$curl https://getsubstrate.io -sSf | bash -s -- --fast Mac OS (Darwin) detected. remote: Repository not found. fatal: repository 'https://github.com/Homebrew/homebrew-versions/' not found

此时,你只需要按照“ Getting Started ”中的手动安装部分进行即可。访问 “https://getsubstrate.io/” 时你可以发现,其内容也就是安装和配置 rust 开发环境而已。

同时,按照文中命令(见下)也是无法正常运行的:

./target/release/substrate

会报以下错误:

2020-05-10 17:15:03 Substrate Node 2020-05-10 17:15:03 ✌️  version 2.0.0-dev-c386dea20-x86_64-macos 2020-05-10 17:15:03 ❤️  by Parity Technologies <admin@parity.io>, 2017-2020 2020-05-10 17:15:03 📋 Chain specification: Flaming Fir 2020-05-10 17:15:03 🏷  Node name: real-battle-0753 2020-05-10 17:15:03 👤 Role: FULL 2020-05-10 17:15:03 💾 Database: RocksDb at /Users/foxgem/Library/Application Support/substrate/chains/flamingfir6/db 2020-05-10 17:15:03 ⛓  Native runtime: node-244 (substrate-node-3.tx1.au10) 2020-05-10 17:15:03 👴 Loading GRANDPA authority set from genesis on what appears to be first startup. 2020-05-10 17:15:03 Cannot create a runtime: Instantiation("Instantiation: Export ext_storage_child_root_version_1 not found") Error: Service(Client(Execution(Other("Instantiation: Export ext_storage_child_root_version_1 not found"))))

请使用以下命令运行:

./target/release/substrate purge-chain --dev ./target/release/substrate  --dev

第一条命令本质上相当于清除数据库的作用,假如你之前曾经运行过但想重新完全开始,可以考虑这条命令。

在接下来的文章中,我会谈谈 Substrate 开发需要的 rust 知识、相关概念,以及 node-template 结构。敬请期待吧,😄。

原文链接


迈向 Substrate 的第一步

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注