Learn about smart contracts in the Polkadot ecosystem in one article
丨密码极客丨
2020-09-19 04:22
本文约1392字,阅读全文需要约6分钟
Polkadot is a heterogeneous multi-chain system developed based on the Substrate blockchain development framework.

Polkadot is a heterogeneous multi-chain system developed based on the Substrate blockchain development framework. Substrate provides the necessary basic functional modules for the development of blockchains. Developers can use Substrate to build parallel chains for specific businesses.

As a relay chain, Polkadot does not support smart contracts itself, but Substrate provides a solution for adding smart contract functions to parachains. Its contract module supports Wasm smart contracts.

Smart contract language ink!

The smart contract platform in the Polkadot ecosystem is dominated by the Wasm virtual machine. From EVM to WebAssembly is the development trend of the smart contract virtual machine. ETH 2.0 will also support the Wasm virtual machine.

ink! is an embedded domain specific language (eDSL for short). It is a blockchain developed based on the Substrate blockchain development framework and provides a solution for writing Wasm smart contracts. ink! is built on the Rust language, follows the rules and syntax of the Rust language, and its design goals are friendly, concise and efficient.

The ink! language consists of three abstraction layers, of which the Core layer contains the core functions for implementing smart contracts, and the Lang layer is based on the Core and Model layers. Most developers only need to use the Lang layer to write smart contract codes.

Smart Contract vs Runtime Module

There are two different approaches to building decentralized applications with Substrate: Substrate Runtime modules and Substrate smart contracts.

Runtime module

The purpose of developing based on the Runtime module is to generate efficient and fast nodes, which provide an underlying access interface to the entire blockchain, can fully control the underlying logic of the blockchain, and can access any storage items in all modules, and Modify and control.

smart contract

smart contract

Substrate smart contracts allow users to add business logic based on the core logic of the blockchain, while establishing a protection mechanism against saboteurs.

Smart contracts are inherently safer for blockchains, because smart contracts cannot directly modify the storage state of the blockchain or other smart contracts, and its capabilities are limited to modifying its own state and making external calls to other smart contracts or Runtime functions. Both calculation and storage state in the process of executing smart contracts will be charged, which ensures that blockchain resources will not be abused and stored infinitely. When the execution of the smart contract fails due to various factors, the smart contract will not update the state, and the transaction will be rolled back. Of course, these management overheads will reduce the efficiency of smart contract execution and increase the cost of operation.

Choice of Coinversation

Both the Substrate Runtime module and the Substrate smart contract are tools for solving problems. As for which tool to choose to solve the problem, it depends on the needs of the problem itself and the cost of development, deployment and maintenance.

Coinversation Protocol is a synthetic asset issuance agreement and contract trading platform. The main functional modules of the entire system include: using mortgages to cast synthetic assets, decentralized contract exchanges, mortgage pools, fee pools, oracles, and liquidity mining. Among them, Coinpro.MintC (minting center for minting and burning cUSD) and Coinpro.Exchange (decentralized exchange for trading synthetic assets) are the core products of the system. Considering that the core product needs to have a strict resource control mechanism and a transaction rollback protection mechanism, it was decided to use Substrate smart contracts for development.

丨密码极客丨
作者文库