This code pattern showcases blockchain-enabled crowdfunding by showing you how to use a Hyperledger Fabric network to build a platform to aid crowdfunding. This network provides a holistic view of the requirement and its current status -- which helps to address the need more efficiently, and reduces the problems of over-collection or under-collection for a need.
- Setup Blockchain Network using IBM Blockchain Platform(IBP) VS Code Extension.
- Deploy the client application using Fabric Node 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
Please follow the steps to run this application.
git clone https://github.com/IBM/blockchain-enabled-crowdfunding
Install IBP extension in VS Code.
-
Create directory as:
mkdir -p $HOME/chaincode/src/demo
-
Copy the smart contract
chaincode/crowdfunding.go
in$HOME/chaincode/src/demo/
. -
Ensure paths are set correctly. GOPATH as
$HOME/chaincode
, GOROOT as< go install directory >
, and PATH has$GOROOT/bin
. -
Open the
demo
folder in VS Code. -
Click the
IBM Blockchain Platform
extension button. This will show the packaged contracts on top. -
Next, click on the 3 dots and select
Package Open Project
. -
You will be prompted for the package name and version. It’s important to provide the proper version as the smart contract can then be upgraded to deploy a newer version. After you’ve provided this information, the smart contract package will be created.
-
In the left navigation panel, you should be able to see a .cds file named
<package name>@<version>
.
Now you are ready to deploy to the local fabric network. Before you can install the smart contract on the network, you need to first connect to a network.
-
Start the Fabric network (if not done yet) using FABRIC ENVIRONMENTS on the left side of the editor.
-
Once the provisioning is finished and the network is up and running, you will see this in VSCode:
Install
-
In the FABRIC ENVIRONMENTS section, click on
Smart Contracts > Installed > Install
. -
Select the packaged contract in the pop-up.
-
After the install is complete, you should see that the contract is listed under Installed under FABRIC ENVIRONMENTS.
Instantiate
-
In the FABRIC ENVIRONMENTS section, click on
Smart Contracts > Instantiated > Instantiate
. -
Choose the installed smart contract to instantiate.
-
The extension will then ask you which function to call on instantiate - type
init
. -
Next, it will ask you for the arguments to the function. There are none, so just hit enter.
-
The extension will then ask you do you want to use a provide a private data collection configuration file? - Click on
no
. -
Lastly, the extension will then ask you do you want to choose a smart contract endorsement policy. Choose Default (single endorser, any org).
Once instantiation of the contract completes, you should see contract name under Instantiated under FABRIC ENVIRONMENTS.
You can test out the transactions right in the VSCode platform using the Fabric Gateways
section.
Get connection profile and copy to local
directory provided in github repository.
In this repository, a sample connection profile is already provided. Need to change the name/ports wherever required.
The middle-layer uses the Hyperledger Fabric SDK to communicate with a blockchain network. Build the client application using Fabric Node SDK. To start that, perform the following steps.
- Go to directory
fabric-node-sdk-app
- Open file
routes/index.js
- Check
CA
settings atline 205-211
- Check chaincode name and version at
line 219-221
- Save the file
Go to terminal and execute following steps.
cd fabric-node-sdk-app
npm install
PORT=30001 DEPLOY_TYPE=local npm start
You should see the message on your terminal as - Successfully enrolled admin user "admin"
.
-
Run the webapp using the following commands.
cd node-webapp npm install npm start
-
Access the application
You can access the webapp at
http://localhost:3000
. You should see the following on your browser.
Using this application you can perform the transactions to monitor the funds raised, donate the money and view the contributors.