Skip to content

A simple Hyperledger Fabric JAVA sample project with a rest api.

Notifications You must be signed in to change notification settings

SachiHarshitha/HyperledgerFab_Java_Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Concept

Hyperledger Fabric Example Created for JAVA.

IMPORTANT BEFORE CLONE!

On Windows 10 you should use the native Docker distribution and you may use the Windows PowerShell. However, for the binaries command to succeed you will still need to have the uname command available. You can get it as part of Git but beware that only the 64bit version is supported.

Before running any git clone commands, run the following commands:

git config --global core.autocrlf false git config --global core.longpaths true You can check the setting of these parameters with the following commands:

git config --get core.autocrlf git config --get core.longpaths These need to be false and true respectively.

Software Pre-requisites

  • Docker (https://docs.docker.com/get-docker/)
  • Visual Studio Code
    • Plugins : Required to Run
      • Java Extension Pack
      • IBM Blockchain Platform
      • Open Liberty Tools
    • Plugins : To create
      • Tools for Microprofile
      • Microprofile Starter
      • Gradle Language Support
      • Gradle Tasks
  • Java 11 : for the above plugins
  • Java 8 : For the PROJECT** (I flound that the Hyperledger Fabric Java SDK is only stable with Java 8 Version)
  • Maven Compiler (https://www.javatpoint.com/how-to-install-maven)
  • Gradle Compiler (Only required to create a new Gradle Project)

How to Run

  1. Clone the Git into your workspace (**FOLLOW the WINDOWS 10 Special requirements to avoid any issues)

  2. Import the two folders (Chaincode & resp-aoi) seperately into your workspace.

  3. Open the IBM Blockchain Platform Plugin and Create a new environment.

    • Click create new environment. image
    • Select "Create new from template". image
    • Select "1 Org template" image
    • Give a name for the environment.
    • Select Channel Capability version 2.0
    • Finally you will be able to see the new environement you created is avalable in the FABRIC ENVIRONMENTS tab.
    • Click on the new environment and it will be created. (New Docker Container will run in background.)
  4. Package the new chaincode.

    • Goto the SMART CONTRACTS tab in the IBM Blockchain Platform plugin.
    • Click the three dot icon and select "Package Open Project".** Make sure the Chaincode folder is added to your worksapce. image
    • Select the Chaincode Project from the drop down menu. image
    • Select the packaging format "tar.gz" image
    • Set the name to any name you like. I use "asset"
    • Set the version of the package to "0.0.1"
    • Once click enter the package will be created and can be seen under SMART CONTRACTS tab. image
  5. Deploy the new contract into the blockchain.

    • Double click on the new environment you've created. image
    • Once logged into the environment, click "Deploy smart contract" under mychannel. image
    • The "Deploy Smart Contract" Window will open.
    • In the new window select the package you've created before. image
    • Click NEXT and skip both Step 2 and 3.
    • Finally click "Deploy".
  6. Test the chaincode deployment is success

    • Double click on the new gateway under FABRIC GATEWAYS image
    • If the deployment successful you will be able to see the created chaincode functions as shown below. image
  7. Create and enroll a new user.

    • Goto back to the FABRIC ENVIRONMENT.
    • Under Nodes you can find the Org1 Certificate Authority (Org1 CA).
    • Right click on it and then click "Create Identity". image
    • Insert a name (Short name reccomended) Ex. "sachi".
    • Select No to add attributes.
    • If created successfully, you can find the newly created account under FABRIC WALLETS tab. image
  8. Deploy the REST API

    • Goto the "LIBERTY DEV DASHBOARD" in the explorer.
    • If you have already loaded the rest-api folder to your workspace you can find it here. image
    • Right click on the rest-api liberty project and click "Start" image
    • This will let Open Liberty Plugin to compile and start the REST API server.
    • Once the server started, access the API user interface via http://localhost:9080/openapi/ui
  9. Load the Connection settings and wallet to the API in order to access the blockchain.

    • Export the Connection Profile from the FABRIC GATEWAY. image
    • Copy the configurtion file into the below path
      • target\liberty\wlp\usr\servers\rest-api\Users\Shared\Connections
    • Export the Wallet image
    • Copy the new user ID created in the above step 7 into the wallet folder.
      • target\liberty\wlp\usr\servers\rest-api\Users\Shared\Connections\wallet image
  10. Update the Configuration file and user ID in the REST API code.

    • Update the config file name and the user in the Iasset.java file under the below path.
      • src\main\java\Hyperledger\rest\api\openapi\IAsset.java image
    • Save the file and you will be able to see on the Integrated terminal that Open Liberty plugin will automatically compile the files and reload the API.
  11. Test the Functions and Have fun!

Releases

No releases published

Packages

No packages published