Substrate 区块链开发之本地网络启动

Substrate 是一个软件开发工具包 (SDK),它使用基于 Rust 的库和工具,使您能够从模块化和可扩展的组件构建特定于应用程序的区块链。使用 Substrate 构建的特定于应用程序的区块链可以作为独立服务运行,也可以与其他链并行运行,以利用 Polkadot 生态系统提供的共享安全性。Substrate 包含区块链基础设施核心组件的默认实现,让您能够专注于应用程序逻辑。

安装

    https://docs.substrate.io/install/macos/

本地网络启动实操

    https://docs.substrate.io/tutorials/build-a-blockchain/build-local-blockchain/

    https://github.com/substrate-developer-hub/substrate-node-template

克隆仓库

git clone git@github.com:substrate-developer-hub/substrate-node-template.git

    切换目录

    cd substrate-node-template
    

      创建一个新分支

      git switch -c my-learning-branch-2024-03-16
      

        编译

        cargo build --release
        

        Substrate 区块链开发之本地网络启动

          启动本地 Substrate 节点

          ./target/release/node-template --dev --tmp
          

          Substrate 区块链开发之本地网络启动

            启动第一个区块链节点 alice

            ./target/release/node-template --chain local --alice --tmp
            

            Substrate 区块链开发之本地网络启动

              启动第二个区块链节点 bob

              ./target/release/node-template --chain local --bob --tmp
              

              Substrate 区块链开发之本地网络启动

                将链规范转换为原始格式 Convert the chain specification to raw format

                  https://docs.substrate.io/tutorials/build-a-blockchain/add-trusted-nodes/

                ./target/release/node-template build-spec --chain=local --raw > spec.json
                

                  读取spec.json文件的内容,搜索包含“boot”的行,并显示这些行以及它们前后各两行的内容

                  cat spec.json | grep boot -C 2
                  

                  Substrate 区块链开发之本地网络启动

                    启动第二个区块链节点,此命令包含--bootnodes选项并指定单个引导节点,即由 启动的节点alice

                    ./target/release/node-template --chain local --bob --tmp --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWBGJ3YcEgqt2BjFmWDv2fkqWPkKrDreWiGyreA7z72UnW
                    

                    Substrate 区块链开发之本地网络启动

                      polkadot.js. 查看

                        https://polkadot.js.org/apps/#/explorer

                      Substrate 区块链开发之本地网络启动

                        polkadot.js 查看出块信息

                        Substrate 区块链开发之本地网络启动

                          交易之前查询

                          Substrate 区块链开发之本地网络启动

                            交易

                            Substrate 区块链开发之本地网络启动

                              提交交易

                              Substrate 区块链开发之本地网络启动

                                交易之后

                                Substrate 区块链开发之本地网络启动

                                  查询交易后的值

                                  Substrate 区块链开发之本地网络启动