Python: The Choice of Different Blockchain Smart Contract Development Languages

In this article, I will introduce which development languages ​​are used to program smart contracts in the three blockchains of Bitcoin, Hyperledger Fabric, and Ethereum, and provide links to resources for your further study.

Let me first introduce that I have been engaged in Python for nearly 9 years. Next, I will introduce my views on the blockchain. If you do not understand Python, you can harass me: 1547251666. . Or pay attention to WeChat public account: Python from programmer to programmer

bitcoin

Speaking of Bitcoin, everyone may think that it is not a currency! But Bitcoin means something different

Bitcoin was the first real blockchain, but, strictly speaking, it was not friendly to smart contract developers.

Smart contracts can be written on the Bitcoin system using Bitcoin Script, a low-entry programming language. Each Bitcoin address corresponds to a Bitcoin Script program. It looks like this:

Please click here to enter image description

Another higher-level language is Ivy, which compiles to Bitcoin Script. Ivy can help you write custom Bitcoin addresses that are SegWit compatible and can execute arbitrary conditions with the support of the Bitcoin protocol (including signature checking, hash eigenvalues ​​(commitment), and time locks) combination. E.g:

Please click here to enter image description

Ivy's github address: https://github.com/ivy-lang/ivy-bitcoin

The Bitcoin "virtual machine" - the part of the protocol responsible for executing the Bitcoin Script program - is more limited than the virtual machines of other smart contract platforms such as Ethereum or Chain Protocol, and its instruction system is not even Turing-complete . But Bitcoin Script does provide a useful set of basic primitives—signature verification, hashing, and relative and absolute timelocks—plus a free combination of these primitives.

Ethereum

Ethereum is the first blockchain to provide a complete framework for smart contract development, so it is also known as the representative of blockchain 2.0. In fact, the vast majority of current blockchain applications, including ICO token issuance, are smart contract applications based on Ethereum.

Ethereum has four specialized languages ​​that can be used to develop smart contracts:

  • Solidity ,受JavaScript 启发

  • Serpent ,受Python启发

  • Mutan,受Go 启发

  • LLL 受Lisp 启发

这四种语言都是为面向合约编程而从底层开始设计的语言,但从目前的发展来看,Solidity已经称为以太坊智能合约开发当之无愧的首选语言。

Solidity的语法类似于JavaScript,这降低了学习门槛,易于被掌握和使用,因为JavaScript是Web开发者的常用语言。例如,下面是一个使用Solidity开发的简单但完整的智能合约:

请点击此处输入图片描述

合约代码第一行指定该合约使用的Solidity版本为0.4.21,不支持高于0.4.21版本的Solidity特性。

在Solidity中,contract关键字包含的代码段即表示一个智能合约,它拥有一些成员变量和函数,看起来非常类似于传统的面向对象开发中的类。

超级账本fabric

fabric是超级账本大家庭中最成熟的一个区块链项目,主要用于行业链、联盟联或私有链,它不需要通过挖矿来形成共识,因此可以达到很高的交易速度。

在fabric中,智能合约被称为链码(Chaincode),实质上是控制区块链网络中的不同实体或相关方如何相互交互或交易的业务逻辑。简言之,链代码将业务网络交易封装在代码中。可以调用链代码来设置和获取账本或 world state。

超级账本可以使用go、java或者nodejs来开发智能合约,不过支持最好的还是go语言。下面是使用go开发的一个简单地fabric智能合约:

请点击此处输入图片描述

frabric的智能合约可以使用一个go中的类实现,它必须要实现约定的借口Init和Query。

Init 方法 在链代码首次部署到区块链网络时调用,将由部署自己的链代码实例的每个对等节点执行。而只要在区块链状态上执行任何读取/获取/查询操作,就会调用 Query 方法。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326015104&siteId=291194637
Recommended