Introduction to blockchain technology, which programming languages are involved? In this article, we will introduce what development languages are used to program smart contracts in bitcoin, Fabric, and Ethereum, as well as provide links to resources for further learning.

The currency

Bitcoin is the first true blockchain, but it’s not strictly friendly to developers of smart contracts.

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

IF 
    2 <Alices' pubkey> <Bob's pubkey> <Escrow's pubkey> 3 CHECKMULTISIG ELSE "30d" CHECKSEQUENCEVERIFY DROP  pubkey> CHECKSIG
ENDIF
Copy the code

Another higher-level language is Ivy, which can be compiled into Bitcoin Script. Ivy helps you write custom Bitcoin addresses that are SegWit compatible and can perform any combination of conditions supported by bitcoin protocols including signature checking, Hash eigenvalues and time locks. Such as:

contract EscrowWithDeplay{
    sender: PublicKey
    recipient: PublicKey,
    escrow: PublicKey,
    delay: Duration,
    val: Value
}{
    clause transfer(sig1: Signature, sig2: Signature){
        verify checkMultiSig([sender, recipient, escrow],[sig1, sig2])
        unlock val
    }
    clause timeout(sig: Signature){
        verify checkSig(sender, sig)
        verify older(delay)
        unlock val
    }
}
Copy the code

Ivy’s Github address is https://github.com/ivy-lang/ivy-bitcoin

Bitcoin “virtual machines” — the part of the Protocol responsible for executing Bitcoin Script programs — are more limited than virtual machines on other smart contract platforms such as Ethereum or Chain Protocol, and their instruction systems are not even Turing-complete. Bitcoin Script does, however, provide a useful set of primitives — signature verification, hash computation, and relative and absolute time locking — plus the ability to combine them freely.

Super ledger Fabric

Fabric is one of the most mature blockchain projects in the super ledger family, primarily used for industry chains, consortions, or private chains. It does not require mining to form consensus, thus achieving high transaction speeds.

In fabric, smart contracts are called chaincodes, which are essentially business logic that controls how different entities or related parties in a blockchain network interact or transact with each other. In short, chain code encapsulates business network transactions in code. Chain code can be called to set and get the ledger or world state.

Hyperledger can use Go, Java, or NodeJS to develop smart contracts, but go is best supported. Here is a simple Fabric smart contract developed using GO:

package main
 
import "fmt"
import "github.com/hyperledger/fabric/core/chaincode/shim"
 
type SampleChaincode struct {
}
 
func (t *SampleChaincode) Init(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
    return nil, nil
}
 
func (t *SampleChaincode) Query(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
    return nil, nil
}
 
func (t *SampleChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
    return nil, nil
}
 
func main() {
    err := shim.Start(new(SampleChaincode))
    iferr ! = nil { fmt.Println("Could not start SampleChaincode")}else {
        fmt.Println("SampleChaincode successfully started")}}Copy the code

Frabric’s smart contract can be implemented using a class in GO, which must implement the conventions of Init and Query.

The Init method is invoked when chain code is first deployed to the blockchain network and will be executed by each peer that deploys its own chain code instance. The Query method is called whenever any read/get/Query operation is performed on the blockchain state.

Visit here to learn more about smart contract development for Fabric: Fabric Chaincode

The etheric fang

Ethereum is the first blockchain to provide a comprehensive framework for the development of smart contracts, so it is also known as the representative of Blockchain 2.0. In fact, the vast majority of blockchain applications, including ICO coin offerings, are smart contract applications based on Ethereum.

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

  • Solidity, JavaScript inspired
  • Serpent, inspired by Python
  • Mutan, inspired by Go
  • LLL was inspired by Lisp

All four languages were designed from the ground up for contract-oriented programming, but Solidity is now the clear language of choice for Ethereum smart contract development.

The syntax of Solidity is similar to JavaScript, which lowers the barrier to learning and is easy to master and use because JavaScript is a common language for Web developers. For example, here is a simple but complete smart contract developed using Solidity:

Pragma solidity ^ 0.4.21; contract HelloWorld { string hello ="Hello World!!!";
    event say(string _value);
    
    functionsayHello() public { emit say(hello); }}Copy the code

The first line of the contract code specifies that the contract uses Solidity version 0.4.21. Solidity features higher than 0.4.21 are not supported.

In Solidity, the code snippet contained in the contract keyword represents a smart contract with member variables and functions that looks very similar to classes in traditional object-oriented development.

If you want to start learning about Ethereum smart contracts and application development right away, you can visit the excellent online interactive tutorials provided by Wisdom:

  • Ethereum smart contract and application of actual combat development
  • Practical development of decentralized e-commerce application of Ethereum