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 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 ( 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 ( $node-v

win7 install git ( $git version
git version 2.9.3
Win7 Installation Cygwin ( 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

6. Establish GitHub account number

Login GitHub Establish account ( username and password)
Install GitHub Desktop ( $ git config--global "GitHub username" (GitHub username= account) $ git config (show GitHub account)

< GitHub username>
7. Installation Example Learn-chaincode

Browser: Https:// (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 username>\ $git clone https://< GitHub username>/learn-chaincode.git $ ls src\\< 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\\< 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. 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://"
"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": [
"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 (US South) (United Kingdom) (Sydney) :

2. selection [play]
13. &cm_mc_sid_50200000=1473623034#chaincode

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: 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.