Java chaincode configuration for Hyperledger Fabric

Source: Internet
Author: User
Tags stub hyperledger fabric

First, start the process of developing code on the Java chain 1. Make sure you have grandle tools.
2. Download the binary distribution package from the http://gradle.org/gradle-download/
3. Unpack, move to the location you want, add the Grandle Bin directory to the system path
4. Ensure that the GRANDLE-V command can be executed, the version shown is 2.12 or higher
5. Ensure Grandle daemon can be quickly created
6. Make sure you've turned jdk8.0 and also make sure that the Java directory is in your path

7.JDK environment variable to ensure good Configuration

8. From the command line terminal to the Devenv subdirectory, perform vagrant ssh
9. Create and run peer
10. Then you can configure the chain code with the Non-dev mode.

--code on the deployment chain
Peer Chaincode deploy-l java-p/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/java/simplesample- C ' {"Args": ["Init", "a", "M", "B", "200"]} '

--Invoking conversion transactions
Peer Chaincode invoke-l java \
-N 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd647 91679E9 \
-C ' {"Args": ["Transfer", "a", "B", "10"]} '

--Query the values of A and B after conversion

Peer Chaincode query-l java \
-N 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd647 91679E9 \
-C ' {' Args ': [' query ', ' A ']} '
{"Name": "A", "Amount": "80"}


Peer Chaincode query-l java \
-N 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd647 91679E9 \
-C ' {' Args ': [' query ', ' B ']} '
{"Name": "B", "Amount": "220"}

Second, the Dev model to deploy the Java chain code

1. The first three steps are the same as above
2. Create and run the peer process
CD $GOPATH/src/github.com/hyperledger/fabric
Make peer
Peer node start--peer-chaincodedev

3. Open the second vagrant terminal to build the Java shim layer and not send a local maven repo

CD $GOPATH/src/github.com/hyperledger/fabric/core/chaincode/shim/java
Gradle-b Build.gradle Clean
Gradle-b Build.gradle Build

4. To this directory java/simplesample create and run

CD $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/java/simplesample
Gradle-b Build.gradle Build

5. Use gradle-b build.gradle run SimpleSample chaincode

6. Open the third vagrant Terminal on the chain code initialization and invocation transactions
Peer Chaincode deploy-l java-n simplesample-c ' {"Args": ["Init", "a", "M", "B", "200"]} '
Peer Chaincode invoke-l java-n simplesample-c ' {"Args": ["Transfer", "a", "B", "10"]} '
Peer Chaincode query-l java-n simplesample-c ' {' Args ': [' query ', ' A ']} '
Peer Chaincode query-l java-n simplesample-c ' {' Args ': [' query ', ' B ']} '

Third, the development of a new Java chain code

1. Create a new Java project
2. Use the sample column Java chain code project similar to Examples/chaincode/java/simplesample to Build.grade
3. Make sure your main class inherits the Chaincodebase class and implements the following methods from the base class

Public String Run (chaincodestub stub, String function, string[] args)
Public String query (chaincodestub stub, String function, string[] args)
Public String Getchaincodeid ()
Modify the Mainclassname in Build.gradle to point to your new class.
Build this project using the Gradle-b build.gradle build
Run this chaincode the starting a peer in Dev-mode as above using Gradle-b Build.gradle run








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.