Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Since the last half year, we have seen a downturn of the crypto-markets and the rise of public chains. Almost every week, there are a lot teams announcing their plans of launching public chain. The unprecedented passion for public chain makes an illusion that building a public chain just needs to set up several nodes.
However, Rome was not built in a day.
The establishment of a public chain is not an easy task. Even the top cryptocurrency exchange, HUOBI has not given a clear declaration of the launch date after investing 30 million HT to develop the public chain(nearly more than 600 million RMB). Actually, the development of public chain requires very large R&D investment, as well as the technical team support and maintenance cost. Also, it is quite costly to organize a large number of community members to participate in node construction and verification. But, even with such high cost, why increasing people appeal for public chain?
The answer is the diversified demands for the blockchain.
Since one blockchain network cannot meet diversified demands. Some people prefer establish a private consortium while others want to establish a completely transparent consensus networkïŒsome advocate the non-token blockchain ecosystem while others believe the token economy is the future of the whole blockchain world. Thus, it seems impossible to be covered by one blockchain network, leading to the increasing appeal for public chain.
How to balance the contradiction between public chain demand and cost? Parachains comes into being.
Parachain is a simple, easily scalable blockchain whose security is provided by the âmain chain.â
Parachain and mainchain maintain a separate and connected relationship. Under the main chain, they can have their own super nodes, state machines and transaction execution capability.
1. What is Parachain
To understand parachain, Letâs first talk about the public chain.
The public chain refers to the blockchain that anyone in the world can access the system to read data, send identifiable transactions, and compete for accounting at any time. Public chains are often considered as âcompletely decentralizedâ because no individual or institution can control or tamper with the data. Bitcoin is the first public chain in the world, which has its own independent wallet and blockchain browser; and Ethereum is the first public chain with smart contracts, hence, Dapps become an important part of the blockchain ecosystem.
Parachain is abbreviation of parallel public chain, which is another form of public chain. Users can build parachains according to the provided documents. Each parachain is an independent blockchain ecology, where developer can create their own independent wallet, browser, DAPP, issue digital certificate, deploy super nodes.
At the same time, all data and consensus mechanism is stored in the main chain while the execution process including sign, send and broadcast, can be done in the parachain. After the transaction execution, the final transaction hash value need to be recorded on the mainchain, thus, the data on the mainchain is the most authoritative and complete. Parachains are attached to the main chain while maintaining relative independence, building the entire blockchain network ecosystem.
2. Advantages of Parachain
- Ensure the security of the entire blockchain network by tremedous and scattered node distribution.
- Each parachain are equal and independent, thus solving the congestion problem;
- Based on the underlying blockchain technology and the function of public chain, enterprises do not need to spend money on high-cost public chain construction and maintenance;
- Parachain has super node deployment function;
- Can quickly develop and dock N kinds of DAPP, and can quickly issue N kinds of tokens;
- Use the public-licensed economic model of the public chain to help enterprises expand their business ecology and seize the Internet market;
- Support code open source;
3. How to build parallel chains in just 1Â minute
The concept of paravhains is still relatively new, first proposed by Polkadot. In China, this concept was first proposed by FUZAMEI Technology Co., Ltd. Later, Baidu (https://en.wikipedia.org/wiki/Baidu) also cited this concept in its white paper. Even with the increasing attention about this concept and blockchain technology, the applications on parachain are still rare.
Fortunately, we finally found an application case about food traceability on parachain. So today, we will use this case to illustrate how to build a parachain and create smart contracts on it.
There are four main steps as followed:
- Environmental deployment
- Contract compilation
- Contract creation
- Contract call
3.1 Environmental deployment
- Get file
wget https://bty.oss-ap-southeast-1.aliyuncs.com/chain33/paraChain.tar.gz
- Decompress
tar zxvf paraChain.tar.gz
- Configuration file modification
The value of the ParaRemoteGrpcClient entry is:
101.37.227.226:8802,39.97.20.242:8802,47.107.15.126:8802,jiedian2.33.cn
The value of mainnetJrpcAddr is: âhttp://jiedian1.33.cn:8801"
The modifications are as follows:
- Start the chain33Â process
cd paraChain &&Â ./chain33 -f chain33.para.toml
3.2 Contract compilation
To compile contracts using the solidity compiler, the following tools are available: Remix-ide and Intellij-Solidity
Here we use Remix-ide as an example.
Create a new solidity contract and select the compiler version to compile.
Souce: https://chain.33.cn/document/126
After the compilation is successful, you can use ABI, Bytecode to create the contract.
3.3 Contract creation
Use the command line in chain33-cli to create the contract (because the length of the fields of abi and bin is too long, use abiInfo and binInfo instead).
[lyn@localhost build]$Â ./chain33-cliââârpc_laddr âhttp://localhost:8901"âââparaName=âuser.p.evmtest.â evm createâââsol food.sol -c 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -f 0.1 0x0603e1422e171a1afd6d599c59e0cbe010fe1d09d9088e1e6f5ccb09b17d6ef0
View contract creation details based on returned hashes.
Since the code is too long, the complete one can be seen in github https://github.com/lynAzrael/L/blob/master/share/solidity/food_trace.md#3-%E5%90%88%E7%BA%A6%E7%9A%84%E5%88%9B%E5%BB%BA
3.4 Contract CallâââInformation Entry
Letâs start with Pork information entry as an example.
Use chain33-cli for information entry
[lyn@localhost build]$Â ./chain33-cliââârpc_laddr âhttp://localhost:8901"âââparaName=âuser.p.evmtest.â evm call -c 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -e âuser.p.evmtest.user.evm.0x0603e1422e171a1afd6d599c59e0cbe010fe1d09d9088e1e6f5ccb09b17d6ef0â -b âaddPigInfo(\â1CbEVT9RnM5oZhWMj4fxUrJX94VtRotzvs\â,\âpig001\â,\â00001\â,\â500\â,\â20190210\â,\âNanJing\â)â -f 0.010x8ca4d60d713abd6baa3ac653b7d15aa506948e5e6b62fe8196809ca633d6e345
Check if the food information is successfully added by hash
Since the code is too long, the complete one can be seen in github https://github.com/lynAzrael/L/blob/master/share/solidity/food_trace.md#411-%E7%8C%AA%E8%82%89%E4%BF%A1%E6%81%AF%E5%BD%95%E5%85%A5
./chain33-cli evm call -c ââ -f ââ -e âevm contract addressâ -b âabiâ
Since the code is too long, the complete one can be seen in github https://github.com/lynAzrael/L/blob/master/share/solidity/food_trace.md#411-%E7%8C%AA%E8%82%89%E4%BF%A1%E6%81%AF%E5%BD%95%E5%85%A5
3.5 Contract callâââinformation query
Take the ham raw material (pork) as an example
Use the pidId queried in foodInfo for further information query
Since the code is too long, the complete one can be seen in github https://github.com/lynAzrael/L/blob/master/share/solidity/food_trace.md#423-%E7%81%AB%E8%85%BF%E5%8E%9F%E6%9D%90%E6%96%99%E7%8C%AA%E8%82%89%E4%BF%A1%E6%81%AF%E6%9F%A5%E8%AF%A2
4. Conclusion
Parachain has strong scalability and is equipped with public chain functions, such as independent blockchain browser, crypto-wallet. Users can develop Dapps and issue tokens on the parachain. As mentioned above, the food tracebility is a good example to show you how to build a parachain and create smart contracts on it.
For further information about parachain, please follow us.
Twitter: FUZAMEI
Website: 33.cn
Github: https://github.com/33cn/chain33
How to Deploy a Parachain in just 1 minute? was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.