
On October 20, 2020, Cryptogeek launched the first phase of [Polkadot Ecological Series Sharing Session]. We are very honored to invite Dr. Jia Yaoqi, technical director of Parity Asia, to be a guest in the crypto geek live broadcast room, explaining "How to develop blockchain projects based on Polkadot".
secondary title
Speech session
1. How to develop a blockchain system on Polkadot?
figure 1
figure 1
You can take a look at Figure 1. In fact, to develop a blockchain from scratch, you have to consider not only the database formula algorithm, but also a conversion function related to processing various transactions. At the same time, if you want to add some more complex or advanced logic in it, such as zero-knowledge proof, then you need to add these more complex algorithms and functions when linking the development zone.
Then everyone will actually think about how we use what we already have, whether it is public chain technology or alliance chain technology for secondary development. In fact, in the past ten years, especially since the launch of the Bitcoin white paper in 2009 and the launch of the Ethereum system in 2015, you can see that the blockchain can not only be used for payment, but also can be deployed on it. smart contract. Then there are many developers who are doing secondary development based on Bitcoin, as well as some interesting blockchain systems such as this utxo model, and some adjustments based on Ethereum, but these are based on the existing The blockchain is being developed for secondary development to create a system like some new chains. Their biggest problem is that they also have a relatively good development framework for early projects like Bitcoin or Ethereum. In fact, everyone is Changes are made on the basis of the source code, which requires developers to have a relatively high understanding of the source code. At the same time, since these source codes are not well modularized as a framework, it is actually very difficult to develop.
figure 2
figure 2
Because Polkadot is a cross-chain project, in order to help developers develop their own blockchain system faster, we have developed a set of frameworks such as Substrate to facilitate developers to develop such a related block The chain system, we call it a parallel chain. You can see that Substrate actually includes many core components of the blockchain I just mentioned, such as the database layer, network layer, and pluggable consensus protocols.
image 3
image 3
Figure 4
Figure 4
In fact, in addition to being a parachain or parathread of Polkadot, it can also be directly deployed as an independent chain. Especially in the unique domestic environment, you can also use Substrate to build your own alliance chain or private chain corresponding to this kind of business logic, as well as some that have relatively high throughput requirements, which can be targeted at a certain application, such as a game alone Build a chain and deploy it in your own corresponding environment. Of course, when you are developing on Substrate, it is more advantageous that after three years, you can see from this figure that the entire Polkadot ecosystem has grown and developers continue to develop. There are many development ecosystems and tools for Substrate. You can use Polkadot-js. Of course, there is a better block browser built in. You can also use an offline hardware wallet like Parity Signer. .
Figure 5
Figure 5
Figure 6
Figure 6
Then you need this kind of Substrate Runtime for development. As you can see in Figure 6, since Substrate is different from our usual development of smart contracts, then it has some of these development policies that you need to remember. For example, the first point, in Substrate Runtime, if you send an extrinsic, or you treat it as a transaction, when sending a transaction, if there is a problem with the transaction, the transaction will not respond to the status change. Get out.
Then, if solidity is developed on Ethereum, if the transaction execution is unsuccessful, its status will actually be rolled back. This requires that when we develop Substrate runtime, it is best for us to verify his logic first, right? Then write.
Figure 7
Figure 7
For this kind of traits, if you want to quote other related traits, because the entire Substrate is written in Rust, some traits will also be used. If you want to know more about this kind of Rust-related information, you can Check out the relevant courses of Rust on the Internet, or join our Substrate courses, we will introduce some basics related to Rust. Then like storage, you can see that there are actually some relatively simple types and the simplest methods in it. You can learn these simple types or examples that you already have, and then modify them according to your actual situation. Related to this variable name, perform such an operation. At the same time, it is similar to when we write a smart contract. When doing some operations, events must be triggered or issued, so you can also define an event here.
Of course, there is another place here is decl_module, which is actually to define the corresponding runtime functions. I will mention at the end that there are many kinds of tutorials on a website called Substrate.dev. You can follow the tutorial to learn, and do some relatively simple examples to learn in depth, how to define such an event storage and function corresponding to these modules, to complete such a corresponding Runtime, and the corresponding Definition and operation of logic.
4. What is the difference between the Substrate application chain and the smart contract?
Figure 8
Figure 8
Everyone knows that writing smart contracts, especially a smart contract like Solidity on Ethereum, is often due to the limitations of Solidity and Ethereum itself-such as its low storage capacity and high handling fees, and at the same time, like Solidity itself There are also many restrictions, and it may be that only integers can be operated more often.
This is why the popular applications on Ethereum that you see are all related to tokens, not to the broader Web3.0.
When you use Substrate for development, there is no such problem.
Because when you use Substrate to develop, the entire chain is controlled by the developer. So when you are developing, whether it is on-chain or off-chain data, or some corresponding interfaces that Solidity does not have, Substrate can provide one.
And you can also see that the throughput of Substrate itself is relatively high, so it can provide applications with more space for processing transactions and logic.
At the same time, Substrate itself will also provide an off-chain worker, which can help developers of Substrate application development to process related off-chain data faster and realize on-chain processing of off-chain data, thus opening up on-chain and off-chain.
5. Seamless on-chain upgrades without forks
Friends who are familiar with the blockchain industry know that in the past, all public chain projects, including some alliance chain projects, required a hard fork if they wanted to upgrade. Like Bitcoin, especially Ethereum. Everyone knows that due to the "The DAO" incident in 2016, due to the different opinions of the miners, the classic ether was finally separated from Ethereum.
Why do we do chain-related upgrades? This actually involves a computer or programming industry.
Everyone actually defaults to such a phenomenon: no programmer can write code without loopholes.
Whether it is writing traditional applications, blockchain applications, or smart contracts. Usually the more code you write, the more security holes you may have.
Looking back on the past few years, whether it is DEFI or the chain itself, everyone will find many various loopholes, resulting in various property losses for many users.
This makes the blockchain itself need a better upgrade—whether it is an upgrade of the smart contract or the upgrade of the chain itself.
But if we frequently use this kind of hard fork to upgrade, first of all, the time will not be able to catch up, because the upgrade requires "each miner to upgrade his software to the latest version within a short period of time, and then within a certain period of time everyone Together to upgrade to such a version, and finally switch from the old chain to the new chain" is such a logic.
However, due to hard forks, this upgrade mode is extremely costly, and many times may cause your own chain to fork out of other chains.
Then something like Substrate has a seamless on-chain upgrade. In fact, it is to submit a runtime corresponding to the developer to the chain, and then vote on the chain for a validator. You can see that this is actually related to the governance on the chain.
After the voting on the chain is completed, if the majority of people agree to perform a corresponding upgrade, then a Runtime submitted by the developer will be written into the Runtime of the entire chain for a corresponding upgrade.
With such a fork-free chain upgrade, it can ensure that blockchain developers can run their own blockchain with more peace of mind.
image description
Figure 9
6. Off-chain worker
Everyone knows that we have various oracle machines on Ethereum, such as chainlink.
In the past six months, the oracle machine has attracted the attention of various people.
Because Ethereum itself cannot open up channels on and off the chain, if the on-chain wants to obtain off-chain data, such as various token prices, this kind of oracle machine is needed to send the data to the chain.
image description
Figure 10
Then the verification nodes on these chains can directly process the chain data.
In the future, it is possible to form a consensus on the processing results—for example, on the chain, to ensure that off-chain information can be obtained faster and more conveniently, and related calculations can be performed.
In the ecology corresponding to Polkadot or Substrate, such a separate oracle is not necessary. Because the interface of the corresponding off-chain working machine has been well written.
At the same time, you can also see the corresponding scenario: In addition to the off-chain data I just mentioned, there are also some scenarios of using off-chain working machines.
For example, for some relatively large calculations, we can use off-chain workers to complete the results, and then return the results to a corresponding on-chain verifier.
image description
Figure 11
7. How to better access Polkadot?
Earlier I talked about some topics such as how Polkadot uses Substrate for development, what the Runtime written by Substrate looks like, and the advantages of Substrate for development.
Then you may also want to know: If Substrate is used to develop a blockchain system, how can I better access Polkadot?
You can take a look at Figure 12, which is actually a whole framework about Polkadot.
image description
Figure 12
If different chains are connected to the relay chain, they will be connected to the relay chain as a parallel link.
Many relatively large blockchain systems, such as Bitcoin or Ethereum, if they want to access Polkadot, they need to first adjust to a parachain through a bridge, and then communicate with other parachains through the parachain.
As parallel chains, their verification of content or blocks is done through the relevant verification nodes of the relay chain.
Then everyone will ask, what nodes does the parachain itself need? As mentioned in the figure, a type of node called a collator is required.
These nodes are responsible for collecting the blocks corresponding to each parallel chain, and then submitting them to some block verification nodes randomly selected by the relay chain. These block verification nodes will verify the corresponding blocks in the parallel chain.
At the same time, the blockchain written using Substrate also requires another module called Cumulus. You can use Substrate to write this Cumulus, and then make a slight improvement, and you can use Cumulus to connect to the parachain.
image description
Figure 13
8. How does the Web3 Foundation support the ecological development of Polkadot?
Projects in the Polkadot ecosystem are particularly active. You can take a look, whether it is the foundation or Parity, our support for the Polkadot ecological project is very high.
For example, in about March, we have issued more than 100 corresponding Web3 projects, and the support of the Web3 fund market grant.
At the same time, we will also have a builder program to help some relatively mature teams in the community and provide them with a service in the technical and business markets.
image description
Figure 14
In Asia or China, you can see that starting from May this year, we have cooperated with Wanxiang to conduct a Web3 training camp and incubated 15 teams.
Most of these 15 teams have been on the relevant test network and main network. Then things like financing are also very popular.
In the future, we also hope that more and better teams can join our Web3 training camp. We provide technical, commercial and marketing-related support.
There are already more than 100 teams around the world developing blockchain based on Substrate.
As an Asian team or a Chinese team, you can see that in the past period of time, we have provided you with various Chinese materials related to Substrate development.
Whether it is Zhihu column, Polkadot official account, or online and offline activities, including Bilibili live broadcast, everyone is welcome to search Substrate, or search our community, and actively join our activities.
At the same time, we also have some latest activities - for example, at the end of the month we will hold the first web3 conference in China, with the theme of openness, open source, and interconnection.
image description
Figure 15
If you are interested, you can learn such a tutorial to experience Substrate's new development framework—whether it is an upgrade on the chain or a working machine off the chain. And the various modules we provide to build your own blockchain.
question Time
question Time
Question 1 is from Hu Zhimin, head of NetEase’s blockchain innovation business.
Hu Zhimin: As a developer, if you want to start a blockchain business in the Polkadot ecosystem and based on Substrate, you will definitely need some start-up funds. I would like to know the support strategy of the Polkadot official fund for blockchain applications, such as what What kind of projects will enable official investment?
Dr. Jia Yaoqi: Regarding the related projects and teams for the development of Polkadot ecology and machine equipment, as I have just said, both the foundation and parity will provide relatively large support.
In terms of funding, the foundation will evaluate the projects based on their qualifications.
You can apply for a project called Web3 grant. For some relatively good projects, the foundation will provide a support of about 30,000 US dollars.
Of course, more complex projects will also provide higher financial support, but it will take longer to review.
For some relatively mature projects with products or testnets, you can apply for some of our mature and related programs. For example builder program or our web3 bootcamp, web3 training camp. We will provide technical market and business-related guidance and assistance for these projects.
At the same time, we will also contact relevant investors or investors at home and abroad who are more active in the Polkadot ecosystem to help us observe these projects and make some related investments.
question two
question two
Qing Huan: If a parachain is developed, what will be the cost of the subsequent parallel link into the card slot?
question three
question three
Qing Huan: Coinversation uses ink! smart contract development project. At present, it is relatively cumbersome from development tools to smart contract testing to deployment. How can we lower the threshold of these developments in the future?
Dr. Jia Yaoqi: ink! is now in its third edition, you can check it out for details.
Regarding ink! related development, developed modules and related components, we are also gradually developing and improving, so as to facilitate more developers to better use ink! technology for development.
question four
question four
Group 1 member of the Polkadot community: Does the application development of Polkadot or Substrate have to be used as a parallel chain? In this way, each application develops a chain, what should I do if there are not enough slots for the parachain?
Dr. Jia Yaoqi: In addition to the parallel chain, there are actually other methods.
The first method is what I just mentioned, you can go through parallel threads and then access the system.
Parathreads do not require a parachain team to monopolize a slot for more than half a year or two years. It only bids for different blocks as needed, and then writes its own blocks into the Polkadot system.
Of course, there are other ways. If you just build a relatively simple application, you can try to use ink! or Solidity to write smart contracts, and then you can deploy your own smart contracts or related applications on the smart contract parachain. Through the smart contract parallel chain to call and provide data to other parallel chains, you can also take advantage of Polkadot's corresponding cross-chain advantages.
Also, you can also build a separate Substrate chain. In the future, through some way of bridging to some parachains, then the data of one’s own chain can be communicated with other parachains through the parachain.
Roughly speaking, through the above three methods, plus the auction of parachain slots, and then access to Polkadot. There are a total of four ways to access the Polkadot system.