HyperLedger Fabric Java SDK - Wrinting the ChainCode Sample in Java

+1 vote

I want to know the equivalent java code to use Fabric Java SDk for the go chaincode and a way to call it in the EndToEndIT.java test file.

How can I do that?

Apr 3, 2018 in Blockchain by Christine
• 15,790 points
4,494 views
Где Вы ищите свежие новости?
Лично я читаю и доверяю газете https://www.ukr.net/.
Это единственный источник свежих и независимых новостей.
Рекомендую и Вам

2 answers to this question.

0 votes
Best answer

To get started developing Java chaincode

  1. Ensure you have gradle
  2. Download the binary distribution from http://gradle.org/gradle-download/
  3. Unpack, move to the desired location, and add gradle’s bin directory to your system path
  4. Ensure gradle -v works from the command-line, and shows version 2.12 or greater
  5. Optionally, enable the gradle daemon for faster builds
  6. Ensure you have the Java 1.8 JDK installed. Also ensure Java’s directory is on your path with java -version
  7. Additionally, you will need to have the JAVA HOME variable set to your JDK installation in your system path
  8. From your command line terminal, move to the devenv subdirectory of your workspace environment. Log into a Vagrant terminal by executing the following command:

    vagrant ssh

  9. Build and run the peer process.

    cd $GOPATH/src/github.com/hyperledger/fabric make peer peer node start

  10. The following steps is for deploying chaincode in non-dev mode.

    • Deploy the chaincode,
    peer chaincode deploy -l java -n map -p /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/java -c '{"Function": "init", "Args": ["a","100", "b", "200"]}'

6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9

    * This command will give the 'name' for this chaincode, and use this value in all the further commands with the -n (name) parameter
    * PS. This may take a few minutes depending on the environment as it deploys the chaincode in the container,
  • Invoke a transfer transaction,
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/java$ peer chaincode invoke -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{"Function": "transfer", "Args": ["a","b", "20"]}'

c7dde1d7-fae5-4b68-9ab1-928d61d1e346

  • Query the values of a and b after the transfer
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/java$ peer chaincode query -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{"Function": "query", "Args": ["a"]}'
    {"Name":"a","Amount":"80"}
    /opt/gopath/src/github.com/hyperledger/fabric/core/chaincode/shim/java$ peer chaincode query -l java \
    -n 6d9a704d95284593fe802a5de89f84e86fb975f00830bc6488713f9441b835cf32d9cd07b087b90e5cb57a88360f90a4de39521a5595545ad689cd64791679e9 \
    -c '{"Function": "query", "Args": ["b"]}'
    {"Name":"b","Amount":"220"}
  • To develop your own chaincodes, simply extend the Chaincode class (demonstrated in the SimpleSample Example under the examples package)

answered Aug 3, 2018 by Omkar
• 69,220 points
0 votes

The following link: 

 https://github.com/hyperledger-archives/fabric/blob/master/core/chaincode/shim/java/src/main/java/example/Example.java 

gives a version of Chaincode in Java. Hope this helps :)

answered Apr 3, 2018 by Perry
• 17,100 points

Related Questions In Blockchain

+1 vote
1 answer
+1 vote
1 answer
+2 votes
2 answers

How can I traverse the blocks of transactions in hyperledger fabric?

For hyperledger fabric you can use query ...READ MORE

answered May 8, 2018 in Blockchain by Rachel
5,370 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,445 views
+16 votes
4 answers
+1 vote
4 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP