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?
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.
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.
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:
3.1 Environmental deployment
tar zxvf paraChain.tar.gz
The value of the ParaRemoteGrpcClient entry is:
The value of mainnetJrpcAddr is: “http://jiedian1.33.cn:8801"
The modifications are as follows:
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.
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.
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
./chain33-cli evm call -c “” -f “” -e “evm contract address” -b “abi”
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
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.