** Work in progress **
Blockchain enabled Crowdfunding
Demonstrate the use of Hyperledger Fabric for building a collaboration platform for Crowd Funding.
Crowdfunding is practice of funding that operates independently of any government and is a way for people, businesses and charities to raise money. Its a way of raising finance by asking a large number of people each for a small amount of money. People invest simply because they believe in the cause.
Green areas also have a huge role in protection of ecosystems. As forest lands and natural ecosystems reduce just because of the urbanization and creation of the cities, it is necessary to make sure biodiversity is not reducing or at least not becoming extinct. Green areas make cities and neighborhoods more attractive places for people to live and work. Although people like cities, because they are more convenient places for living, they need some rural influence as well, beside lack of plants and trees can even make living impossible.
Here is a blockchain enabled solution for Crowdfunding supporting "Go Green Movement", in which people with a diverse/same portfolios can come forward and be a part of this moment by funding for the cause. This network will give the holistic view of the requirement and its current status. This way a need is catered to in an efficient manner. The problems of over collection or under collection for a need is reduced. The platform brings in trust, accountability and transparency of operations.
When the reader has completed this Code Pattern, they will understand how to:
- Setup blockchain Network using IBM Blockchain Platform
- Interact with blockchain network using Fabric Java SDK
- Build a client application which will interact with blockchain network with the help of Java SDK
Flow
- Setup Blockchain Network using IBM Blockchain Platform on IBM Cloud.
- Deploy the client application using Fabric Java SDK. It works as middle layer and exposes REST API.
- Deploy Web UI application built using NodeJs.
- User can perform following task using the web interface which internally interacts with Blockchain Network with the help of middle layer.
- Current status of Funds raised
- Donate for the cause
- View all Supporters who have donated
Pre-requisites
- IBM Cloud Account
- Git Client - needed for clone commands.
- Maven
- Nodejs
Steps
Follow these steps to setup and run this code pattern. The steps are described in detail below.
- Get the code
- Create IBM Cloud Services
- Setup Hyperledger Fabric Network using IBM Blockchain Platform
- Build the client application using Fabric Java SDK
- Build and deploy webapp
- Analyze the Results
1. Get the code
-
Clone the repo using the below command.
git clone https://github.com/IBM/blockchain-enabled-crowdfunding
-
In this repository,
- Chaincode : Go lang based smart contract with application logic that has to be installed on the network.
- Client code using Fabric Java SDK: application code built using Fabric Java SDK to invoke and query chaincode on the hyperledger fabric network. The operations are exposed as ReST APIs when deployed enabling other applications to consume.
- Web application code: NodeJS based application code to render UI and integrates with the REST APIs exposed by the client application built on Fabric Java SDK.
2. Create IBM Cloud Services
Create IBM Kubernetes Service
Create a Kubernetes cluster with Kubernetes Service using IBM Cloud Dashboard. This pattern uses the free cluster.
Note: It can take up to 15-20 minutes for the cluster to be set up and provisioned.
Create IBM Blockchain Platform Service
Create IBM Blockchain Platform service instance using IBM Cloud Dashboard.
3. Setup Hyperledger Fabric Network on IBM Blockchain Platform on IBM Cloud
In this step, we will setup the Hyperledger Fabric network using IBM Blockchain Platform as explained below.
Create Hyperledger Fabric Network on IBM Blockchain Platform
The blockchain network should consist of two organizations with single peer each and an orderer service for carrying out all the transactions. For detailed steps to create fabric network, please refer to the quick start guide for IBM Blockchain Platform.
Deploy Smart Contract on IBM Blockchain Platform
Smart contract(chaincode) is available here.
Package the smart contract
To package follow the instructions provided here as step 12. For your convenience, packaged smart contract(.cds) is also provided in repo under chaincode
directory. Use this file to install smart contract.
Install and Instantiate smart contract
- Install smart contract using the
.cds
file generated/downloaded as explained in previous step. - Instantiate the smart contract. Function name to be provided during instantiation is
init
and no parameters OR we can leave it blank as we are using the default function name (init) only.
Download connection profile
Instantiation of smart contract has to be followed by integrating the blockchain network with Fabric Java SDK. Follow the below steps to download Connection Profile
.
-
Under
Instantiated smart contracts
section, click on the three vertical dots for your smart contract as shown. Click onConnect with SDK
option. -
Provide the
MSP name
andCertificate Authority
. Scroll down and click onDownload Connection Profile
. -
Rename the downloaded json file as
connection_profile.json
. -
Place this file in
fabric-java-sdk-app/src/main/resources/
. It gets loaded throughConnectionProfileLoader.java
3. Build the client application using Fabric Java SDK
Here, we use the Fabric Java SDK App to build a client to invoke and query chaincode on the hyperledger fabric network.
Open the manifest.yml
file under fabric-java-sdk-app
directory. Under env
section, provide the valid credentials for an user who can execute transactions in the network. Also update Organization Affiliation and Chaincode name.
applications:
- name: blockchain-enabled-crowdfunding-java
random-route: true
memory: 1024M
path: target/crowdfunding-java.war
buildpack: java_buildpack
env:
admin: <admin-username>
adminpw: <admin-password>
OrgAffiliation: <affiliation>
ChainCodeName: <Chaincode-Name>
Note: In this pattern, we are using admin credentails directly for executing transactions and not registering a new user.
Next, on the command terminal go to blockchain-enabled-crowdfunding
directory, and execute the below commands:
cd fabric-java-sdk-app
mvn clean install
ibmcloud cf push
Login to IBM Cloud
. On the Dashboard
, verify that an app blockchain-enabled-crowdfunding-java
is running fine.
Make a note of this Fabric Java SDK client application's url. On IBM Cloud dashboard, click on the application. When application page opens, click on Visit App URL
. Now make a note of the url, as shown on the browser, even if the page shows some error. If the url ends with a /
then remove the trailing forward slash. This url should be provided in web application that interacts with this Fabric Java SDK client application.
4. Build and deploy webapp
A web application is provided to perform various operations like Donate Money
, View Supporters
etc. Web appication code can be found under webapp
directory.
This web application invokes rest interfaces implemented in Fabric Java SDK client application as explained above. Hence the web application needs Fabric Java SDK client application url for rest invocations.
Perform the following steps:
-
Run the below command.
cd webapp
-
Update the Java application url (as noted in section 3) in
config.js
file ofwebapp
directory. -
Deploy the application to IBM Cloud using the command:
ibmcloud cf push
Deployment might take a few minutes to complete. Ensure that there are no errors while deploying the application.
5. Analyze the Results
Login to IBM Cloud
. On the Dashboard
, verify that an app blockchain-enabled-crowdfunding-webui
is running fine. Click on the web application entry. When application page opens, click on Visit App URL
. Web application page opens.
It shows the crowdfunding project details, current status of funds raised and the tasks that you can perform.
There are no donations done by default. To donate, click on Donate
.
Provide the required details and click on Donate Now
to donate. A pop up message appears with the result of the donation request . Click OK
. Once done click on Back
button to return to tasks list.
Click on View Supporters
to view the list of supporters who have donated, as shown in below image.
Learn More
License
This code pattern is licensed under the Apache Software License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.