Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Solidity Intelligent contract

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to realize Solidity intelligent contract". In daily operation, I believe many people have doubts about how to realize Solidity intelligent contract. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to realize Solidity intelligent contract". Next, please follow the editor to study!

Bitcoin

Bitcoin is the first real blockchain, but it is strictly unfriendly to developers of smart contracts.

Smart contracts can be written on bitcoin systems in Bitcoin Script, a low-threshold programming language. Each bitcoin address corresponds to a Bitcoin Script program. It looks like this:

IF 2 CHECKSIGENDIF

Another higher-level language is Ivy, which can be compiled into Bitcoin Script. Ivy can help you write custom bitcoin addresses that are compatible with isolated witnesses (SegWit) and can perform any combination of conditions with the support of bitcoin protocols, including signature checking, hash eigenvalues (commitment), and time locks. For example:

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}}

Bitcoin "virtual machines"-part of the protocol responsible for executing Bitcoin Script programs-are more limited than those on other intelligent contract platforms such as Ethernet Fong or Chain Protocol, and their instruction system is not even Turing complete. But Bitcoin Script does provide a useful set of basic primitives (primitives)-- signature verification, hashing, and relative and absolute time locks-- as well as free combination of these primitives.

Super ledger fabric

Fabric is the most mature block chain project in the super ledger family, which is mainly used for industry chain, alliance or private chain. It does not need to dig mines to form a consensus, so it can achieve a high transaction speed.

In fabric, intelligent contract is called chain code (Chaincode), which is essentially the business logic that controls how different entities or related parties in the block chain network interact or trade with each other. In short, chain code encapsulates business network transactions in code. You can call the chain code to set and get the ledger or world state.

Super books can use go, java or nodejs to develop smart contracts, but go is the best language to support. 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)) if err! = nil {fmt.Println ("Could not start SampleChaincode")} else {fmt.Println ("SampleChaincode successfully started")}}

Frabric's smart contract can be implemented using a class in go, which must implement the agreed excuses of Init and Query.

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

Visit here to learn more about fabric's smart contract development: Fabric Chaincode

Tai Tai Fong

Etay Fong is the first blockchain to provide a comprehensive intelligent contract development framework, so it is also known as blockchain 2.0. In fact, the vast majority of blockchain applications, including ICO token issuance, are intelligent contract applications based on Ethernet Square.

Etay Square has four special languages that can be used to develop smart contracts:

Solidity, inspired by JavaScript

Serpent, inspired by Python

Mutan, inspired by Go

LLL is inspired by Lisp

These four languages are designed from the bottom up for contract-oriented programming, but from the current development, Solidity has become the well-deserved preferred language for intelligent contract development in Ethernet Square.

The syntax of Solidity is similar to that of JavaScript, which lowers the barriers 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 leading contract HelloWorld {string hello = "HelloWorld!!"; event say (string _ value); function sayHello () public {emit say (hello);}}

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

In Solidity, the contract keyword contains code snippets that represent an intelligent contract with member variables and functions that look very similar to classes in traditional object-oriented development.

At this point, the study on "how to realize the Solidity intelligent contract" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report