Substrate 区块链开发之本地网络启动
Substrate 区块链开发之本地网络启动 What is 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 克隆仓库 1 git clone git@github.com:substrate-developer-hub/substrate-node-template.git 切换目录 1 cd substrate-node-template 创建一个新分支 1 git switch -c my-learning-branch-2024-03-16 编译 1 cargo build --release 启动本地 Substrate 节点 1 ./target/release/node-template --dev --tmp 启动第一个区块链节点 alice 1 ./target/release/node-template --chain local --alice --tmp 启动第二个区块链节点 bob 1 ./target/release/node-template --chain local --bob --tmp 将链规范转换为原始格式 Convert the chain specification to raw format https://docs.substrate.io/tutorials/build-a-blockchain/add-trusted-nodes/ 1 ./target/release/node-template build-spec --chain=local --raw > spec.json 读取spec.json文件的内容,搜索包含“boot”的行,并显示这些行以及它们前后各两行的内容 1 cat spec.json | grep boot -C 2 启动第二个区块链节点,此命令包含--bootnodes选项并指定单个引导节点,即由 启动的节点alice 1 ./target/release/node-template --chain local --bob --tmp --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWBGJ3YcEgqt2BjFmWDv2fkqWPkKrDreWiGyreA7z72UnW polkadot.js. 查看 https://polkadot.js.org/apps/#/explorer polkadot.js 查看出块信息 交易之前查询 交易 提交交易 交易之后 查询交易后的值