Substrate 基础知识(knowledge base)

https://substrate.dev/docs/en/

Getting Started

Overview

欢迎来到Substrate区块链开发的精彩世界! 这是Substrate知识库,Substrate开发者的官方文档中心。本资源的目的是帮助读者理解Substrate区块链开发的错综复杂的关系。本指南分为几个部分,解释了Substrate构建的原则和设计决策,以及成为高效Substrate区块链开发人员所需的特定技能。

需要的一些专业知识
为了充分利用Substrate,您应该具备良好的计算机科学知识和基本的区块链概念。应该熟悉诸如区块头、区块、客户机、哈希、交易和签名之类的术语。Substrate是建立在Rust编程语言上的,Rust它利用了新颖的设计模式,使代码的开发是安全和快速的。虽然你并不需要知道Rust就能开始Substrate开发,但是对Rust有良好的理解将使你成为一个更好的Substrate开发者。查看Rust社区提供的优秀资源,以培养您的Rust开发技能。

Substrate采用模块化的方法进行区块链开发,并定义了一组丰富的原语,允许开发人员使用功能强大、熟悉的编程习惯用法。

Usage

Substrate设计用于以下三种方式之一:

  1. 使用Substrate节点(With the Substrate Node):可以运行预先设计的Substrate节点并配置其创世区块。在本例中,您只需要提供JSON文件并启动自己的区块链。JSON文件允许您配置构成Substrate节点运行时的模块的起源状态,例如:余额(Balances)、锁定(Staking)和Sudo。您可以在 Create Your First Substrate ChainStart a Private Network 教程中了解更多有关启动Substrate节点的信息。
  2. 使用Substrate框架(With Substrate FRAME):您可以使用框架(模块化实体的运行时聚合框架)轻松创建自己的自定义运行时,这是用来构建Substrate节点的。这为您在区块链的逻辑之上提供了大量的自由,并允许您配置数据类型,从各个模块(称为“托盘”)中选择库,甚至可以添加自己的自定义托盘。Substrate Developer Hub Node Template 是类似项目的一个有用的起点。要了解更多信息,请参阅 Build a dAppAdd a Pallet 的教程。
  3. 使用Substrate底层核心(With Substrate Core):整个框架系统可以被忽略,并且运行时可以从头设计和实现。这可以用任何可以支持WebAssembly的语言来完成。如果运行时可以与Substrate节点的抽象块编写逻辑兼容,那么您可以从Wasm blob中构造一个新的genesis块,并使用现有的基于Rust的Substrate客户端启动链。如果没有,那么您需要更改客户端的区块编写逻辑,甚至可能需要更改区块头和区块序列化格式。在开发工作量方面,这是迄今为止最难使用Substrate的方式,但是也给了你最自由的创新空间。

Substrate允许开发者在设计决策的每一步中,都可以在技术自由和易于开发之间做出选择。下图说明了这种灵活性的本质。
在这里插入图片描述

Next Steps

Architecture

在这里插入图片描述
Substrate客户端是一个运行了基于Substrate的区块链节点的应用程序。它由几个组件组成,包括但不限于以下内容:

  • Storage: used to persist the evolving state of a Substrate blockchain. The blockchain network allows participants to reach
    trustless consensus about the state of storage. Substrate ships with a simple and highly efficient key-value storage mechanism.
  • Runtime: the logic that defines how blocks are processed, including state transition logic. In Substrate, runtime code is compiled to Wasm and becomes part of the blockchain’s storage state. This enables one of the defining features of a Substrate-based blockchain: forkless runtime upgrades. Substrate clients may also include a “native runtime” that is compiled for the same platform as the client itself (as opposed to Wasm). The component of the client that dispatches calls to the runtime is known as the executor, whose role is to select between the native code and interpreted Wasm. Although the native runtime may offer a performance advantage, the executor will select to interpret the Wasm runtime if it implements a newer version.
  • Peer-to-peer network: the capabilities that allow the client to communicate with other network participants. Substrate uses the Rust implementation of the libp2p network stack to achieve this.
  • Consensus: the logic that allows network participants to agree on the state of the blockchain. Substrate makes it possible to supply custom consensus engines and also ships with several consensus mechanisms that have been built on top of Web3 Foundation research.
  • RPC (remote procedure call): the capabilities that allow blockchain users to interact with the network. Substrate provides HTTP and WebSocket RPC servers.
  • Telemetry: client metrics that are exposed by the embedded Prometheus server.

Installation

本页将指导您完成为Substrate开发准备计算机所需的两个步骤。由于Substrate是用Rust编程语言构建的,因此首先需要做的是为计算机准备Rust开发环境—这些步骤将根据计算机操作系统的不同而有所不同。一旦配置了Rust,您将使用它的工具链与Rust项目进行交互;Rust工具链的命令对于所有支持的、基于Unix的操作系统都是相同的。

1. Build Dependencies

2. Rust Developer Environment

Automated getsubstrate.io Script
Manual Rust Configuration

Test Your Set-Up!

Troubleshooting Substrate Builds

Getting Started on Windows

注意:Windows系统下进行substrate的native开发并没有得到很好的支持!强烈建议使用Windows的Linux子系统(WSL)并遵循Ubuntu/Debian系统的说明进行开发。

在Unix-based的操作系统(例如macOS或Linux)上进行Substrate开发是最容易的。Substrate的教程处方中的示例使用Unix风格的终端来演示如何从命令行与Substrate交互。

Glossary

Substrate Key Concepts

Runtime Development

Pallets
FRAME
Macros
Metadata
Storage
Origin
Execution
Events
Errors
Transaction Fees and Weights
Benchmarking
Debugging
Tests
On-Chain Randomness
Upgrades

Smart Contracts

Overview
Contracts Pallet
EVM Pallet
F.A.Q.

Integrate

Polkadot-JS
Client Libraries
Chain Specification
The Subkey Tool
Memory Profiling

Advanced

Account Information
SCALE Codec
Consensus
The Block Import Pipeline
Runtime Executor
Cryptography
Storage
SS58 Address Format
Why are there no Hash collections in sp_std?

Contribute

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值