Use IBM Bluemix Blockchain service to develop chaincode in Blockchain network

Source: Internet
Author: User
Tags install go git clone

#使用IBM Bluemix Blockchain service in Blockchain network development ChaincodeAuthor: Zhao Email:chenlin2@ms9.hinet.net block Chain (blockchain) technology, the biggest feature is [to centralize management, no Server], all decisions by the majority of participants to reach [consensus] after the decision, the benefit is to reduce the operating costs of the system, and through cryptography encryption and decryption, digital signature and hash (hashing) Ensure system transactions are secure, IBM consolidates Bluemix's Watson IoT & Blockchain Service (ref. 2), the example of the contract of carriage of goods to ensure that the transported items are at temperatures below C of 0 degrees Celsius, If higher than 0 degrees C then the responsible unit must be responsible for compensation for the loss of goods liability; The temperature sensor can be embedded in the packaging of the goods, and in the different industries (factories, sea, land, customs, banks, grocers) that are involved in the carriage of goods, the current situation (e.g. temperature, location) of goods transported by the Internet can be received. To carry out the relevant business, the land Company can determine when to send a car to the port to receive the port of the container; Customs broker can predict the arrival of goods to the destination time in order to handle customs action, the bank through the customs broker, the grocer's confirmation payment to the factory. If the temperature exceeds 0 degrees C above, the start-up energy Intelligent Contract (Chaincode) will record the temperature in block. In addition to monitoring temperature, each phase of events must be a multi-party agreement to join the block blockchain, the system operation is not centralized management agencies to participate in , but to operate the system after a consensus has been reached among all participants. The Intelligent contract (Chaincode) is composed of the program code, Ibm-blockchain is written in Golang Chaincode, the event occurs then the starting block should be chaincode. The following example is the development and execution of CHAINOCDE using the Swagger API page in the IBM bluemix Blockchain service environment. Development environment: Win7 (BIT), Bluemix, blockchain, Golang 1.win7 installed on win7 install Go (https://golang.org/dl/) 2. Set the installation path to the system variable after installation

3. Create working directory D:\GoProjects, set up Gopath variable $ set gopath=d:\goprojects $ go version

Go version go1.7 windows/amd64 4 win7 installation Nodejs, NPM (https://nodejs.org/en/) $node-v

v6.5.0
$NPM-V
2.15.9
win7 install git (https://git-scm.com/download/win) $git version
git version 2.9.3
Win7 Installation Cygwin (https://cygwin.com/install.html) Set the installation executable directory (D:\cygwin64\bin) to the system path variable 5. Installation of Super Ledger (Hyperledger) gasket Code (SHIM Code) $CD D:\GoProjects $ Go get Github.com/hyperledger/fabric/core/chaincode/shim

6. Establish GitHub account number

Login GitHub Establish account (https://github.com/record username and password)
Install GitHub Desktop (https://desktop.github.com/) $ git config--global user.name "GitHub username" (GitHub username= account) $ git config user.name (show GitHub account)

< GitHub username>
7. Installation Example Learn-chaincode

Browser: Https://github.com/IBM-Blockchain/learn-chaincode (click to select Fork)
8. Confirm that Learn-chaincode has been clone to your repository in Bluemix blockchain

Service environment must use Chaincode installed in GitHub.

9. GitHub Learn-chaincode repository clone to lcoal machine $cd: \goprojects $mkdir-P Src\github .com\< GitHub username>\ $cd src\github.com\< GitHub username>\ $git clone https:// github.com/< GitHub username>/learn-chaincode.git $ ls src\github.com\< GitHub username>\

The Chaincode paradigm under the Learn-chaincode directory has 2 versions, start (Chaincode with framework only), finished (already developed CHAINCDE); To develop chaincod in local E first to determine in the local environment can compile Chaincode_start.go $cd d:\goprojects\src\github.com\< yourgithubid >\ Learn-chaincode\start $go build./(normal end must not have any text or error output to the screen)

(if there is a bug correction) *shim. Chaincodestub => Shim. Chaincodestubinterface 11. Perform test Chaincode using the Swagger UI interface of the Bluemix blockchain service; Log on to IBM Bluemix:https://console. ng.bluemix.net/Point Select Sign up; Login after registration (30 days probation free) will be username and password records.

Establish organization name

Create space name organization, Space Region (US South)

12. Point selection Record (CATALOG) => SELECT [Blockchain IBM BETA] service

Service name:myblockchain => CREATE

14. Select Service Crendentials (display service crendentials content)

15. Click to select Launch

16. Click Logs to open the log file

Display log file contents

17. Click Networks Display Chaincode ID (the following figure shows no chaincode at present)

18. DOT Select APIs display API interactive documentation (enter Swagger API page)

19. Expand +network ' s Enroll IDs record: id=user_type1_736394e032, Secret=7a59adadco (with multiple IDs available)

20. Click Registrar-> post/resgistrar

21. With id=user_type1_736394e032, Secret=7a59adadco registered =>[try is out]

{
"Enrollid": "user_type1_736394e032",
"Enrollsecret": "7a59adadco"
}
22. Response [Login successful] as follows: Show registration success

23. Click Chaincode => get/chain

24. Through rest interface, the user sends out requests to deploy the GitHub Chaincode to blockchain network node (peer), the following is the request format, and the Deployspec field is posted.

Path: Step 9
Securecontext: Step 21
{
"Jsonrpc": "2.0",
"Method": "Deploy",
"Params": {
' Type ': 1,
"Chaincodeid": {
"Path": "Https://github.com/xxxxxxxxxxx/learn-chaincode/finished"
},
"Ctormsg": {
"Function": "Init",
"Args": [
"Hi There"
]
},
"Securecontext": "User_type1_xxxxxxxxxxxxxxxxxxxxx"
},
"id": 1
}
25. Return Chaincode ID (128 character) to the result of Chaincode deploy to peer

To perform the chaincode that is installed in peer, refer to the Chaincode ID

26. To execute the Chaincode query function, you will execute the query document and paste into the Queryspec field

Chaincodeid: Step 25
Securecontext: Step 21
{
"Jsonrpc": "2.0",
"Method": "Query",
"Params": {
' Type ': 1,
"Chaincodeid": {
' Name ': ' Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx '
},
"Ctormsg": {
"Function": "read",
"Args": [
"Hello_world"
]
},
"Securecontext": "User_type1_xxxxxxxxx"
},
"ID": 2
}
chaincode Query function Response Hi there is the result of previous Chaincode deploy

28. To execute the Chaincode invoke function, the invoke document is executed and the Invokespec field is pasted

Chaincodeid: Steps
securecontext: Steps
 {
    "JSONRPC": "2.0", "Method
    ": "Invoke",
    "params": {
        " Type ": 1,
        " Chaincodeid ": {
            " name ":" Xxxxxxxxxxxxxxxxxxxxxx "
        },
        " Ctormsg ": {
           " function ":" Write ",
           " args ": [
                " Hello_world ",
                " Go Away "
            ]
        },
        " Securecontext ":" User_type1_xxxxxxxxx "
    },
    "id": 3
  }

Chaincode's invoke function responds as follows and sets [key value of hello_world] to go away

30 Repeat step 26 (Execute Chaincode query function) to show that [key value of Hello_world] has been changed to go away

31. The advantage of using the Swagger API page is that you do not have to wait until the system is completed to test the correctness of the Chaincode, Blockchcin Service is currently a beta, there will be a problem of instability. Appendix:

1.bluemix Global System Maintenance status
2.Bluemix selectable Region
Api.ng.bluemix.net (US South)
Api.eu-gb.bluemix.net (United Kingdom)
Api.au-syd.bluemix.net (Sydney) :

1.https://github.com/ibm-blockchain/learn-chaincode
2.https://www.ibm.com/internet-of-things/iot-news/announcements/private-blockchain/point selection [play]
3.https://console.ng.bluemix.net/docs/services/blockchain/ibmblockchain_tutorials.html
4.https://github.com/hyperledger
5.http://www.ibm.com/blockchain/for_developers.html
6.https://github.com/ibm-blockchain/chaincode-investigator
7.https://console.ng.bluemix.net/docs/services/iot/blockchain/dev_blockchain.html
8.https://console.ng.bluemix.net/docs/services/iot/bl_blockchain_integration.html
9.https://console.ng.bluemix.net/docs/services/iot/reference/extensions/index.html
10.http://bramwelt-fabric.readthedocs.io/en/latest/faq/chaincode_faq.html
11.http://www.multichain.com/blog/2016/04/beware-impossible-smart-contract/
12.https://github.com/ibm-watson-iot/blockchain-samples/tree/master/simple_contract_hyperledger
13.https://github.com/hyperledger/fabric/blob/master/docs/api/coreapi.md?cm_mc_uid=61030309207314713163325 &cm_mc_sid_50200000=1473623034#chaincode
14.https://1drv.ms/f/s!akbmzwp0h-vxbr7h1utnstmcpwi
15.https://1drv.ms/b/s!akbmzwp0h-vxazobosvz8ngmlpm
16.https://1drv.ms/b/s!akbmzwp0h-vxblk7fojh9il5hhc
17.https://www.youtube.com/watch?v=24jaf9eu1mk&list=uuotze-b_je_ovy9k9uhz4ba&index=74
18.https://www.youtube.com/watch?v=wsmj-rwuo8i&list=uuotze-b_je_ovy9k9uhz4ba&index=73
19.https://www.youtube.com/watch?v=sosn6mvgh60&list=uuotze-b_je_ovy9k9uhz4ba&index=72

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.