This guide covers prerequisites, setup instructions, and steps for developing a Node.js application integrated with Hyperledger Fabric.
-
Homebrew: Install Homebrew if it is not already installed.
-
Docker Desktop: Install Docker Desktop.
-
Node.js, jq, and npm: Install these packages via Homebrew:
brew install node jq
- Docker: Install Docker using your preferred package manager (e.g.,
apt-get
,yum
). - Node.js, jq, and npm: Install with your package manager (e.g.,
apt-get
,yum
).
Note: If you have already installed these, you can skip this step. Otherwise, run:
curl -sSL https://bit.ly/2ysbOFE | bash -s
-
Add Fabric binaries and configuration to your PATH by appending the following lines to your
.zshrc
or equivalent:echo 'export PATH=$PWD/bin:$PATH' >> ~/.zshrc echo 'export FABRIC_CFG_PATH=$PWD/config' >> ~/.zshrc echo 'export CORE_PEER_TLS_ENABLED=true' >> ~/.zshrc echo 'export CORE_PEER_LOCALMSPID=Org1MSP' >> ~/.zshrc echo 'export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/test-network/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem' >> ~/.zshrc echo 'export CORE_PEER_MSPCONFIGPATH=${PWD}/test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp' >> ~/.zshrc echo 'export CORE_PEER_ADDRESS=localhost:7051' >> ~/.zshrc
-
Apply changes by sourcing the profile:
source ~/.zshrc
-
Add Fabric binaries to your PATH by appending the following lines to your
~/.bashrc
or equivalent:echo 'export PATH=$PWD/bin:$PATH' >> ~/.bashrc echo 'export FABRIC_CFG_PATH=$PWD/config' >> ~/.bashrc echo 'export CORE_PEER_TLS_ENABLED=true' >> ~/.bashrc echo 'export CORE_PEER_LOCALMSPID=Org1MSP' >> ~/.bashrc echo 'export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/test-network/organizations/peerOrganizations/org1.example.com/tlsca/tlsca.org1.example.com-cert.pem' >> ~/.bashrc echo 'export CORE_PEER_MSPCONFIGPATH=${PWD}/test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp' >> ~/.bashrc echo 'export CORE_PEER_ADDRESS=localhost:7051' >> ~/.bashrc
-
Apply changes by sourcing the profile:
source ~/.bashrc
find test-network -type f -not -path "*.git*" -exec dos2unix {} +
-
Navigate to the test network directory:
cd test-network
-
Stop any existing network (if running):
./network.sh down
-
Start the test network:
./network.sh up -ca
-
Create a channel:
./network.sh createChannel -c mychannel
-
Deploy the chaincode using Node.js:
./network.sh deployCC -ccn basic -ccp ../chaincode-javascript/ -ccl javascript
-
Navigate to the application directory:
cd backend/src
-
Install the required Node.js packages:
npm install
-
Run the application:
node app.js
-
Enroll Admin User:
node caActions.js admin <orgName>
-
Register and Enroll Application User:
node caActions.js user <orgName> <username>
-
Check Docker containers to ensure the Hyperledger Fabric components are running:
docker ps
-
Interact with the application to confirm that it communicates with the Hyperledger Fabric network as expected.
This README provides a complete guide to setting up and using Node.js as an application developer with Hyperledger Fabric on macOS and Linux systems.