Skip to content

Hyperledger Fabric Development README

pdhuff edited this page Nov 17, 2020 · 6 revisions

Hyperledger Fabric Installation

Hyperledger Fabric Test Network

Develop and Test your Chaincode in Node.js

  • First test your ability to deploy chaincode. Supported chaincodes for deployCC are basic, events, ledger, private, sbe, and secured. These are just samples, but this greatly simplifies the deployment process. In ~/fabric-samples/test-network/
    • ./network.sh deployCC -ccn basic -ccl javascript
  • Add your own application in your home directory and then edit fabric-samples/test-network/scripts/deployCC.sh. Add the following at line 60 (approximately):
elif [ "$CC_NAME" = "" ]; then
    println $'\e[0;32m'YOURCHAINCODE$'\e[0m' chaincode
    CC_SRC_PATH="../../YOURCHAINCODE_DIR"
  • If you are working in WebStorm, use git to transfer your local code edits to your server. Create the project on GitHub.
git init
git add .
git commit -m "First commit"
git remote add origin https://github.com//
  • It's helpful to see stdout on the docker logs to see any nodejs errors. You can enable this in ~/fabric-samples/test-network/docker/docker-compose-test-net.yaml
    • Add CORE_VM_DOCKER_ATTACHSTDOUT=true on lines 77 and 115 (approximately). This will allow nodejs errors to become visible in docker logs
  • When making changes to the chaincode, perform the following. (after running git commit on your development workstation and then git pull on the server)
./network.sh down
./network.sh up createChannel -c mychannel -ca
./network.sh deployCC -ccn threat -ccl javascript -cci InitLedger
  • You can also test the chaincode manually using the peer command peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/<USER>/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n <CHAINCODE NAME> --peerAddresses localhost:7051 --tlsRootCertFiles /home/<USER>/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles /home/pdhuff/fabric-samples/test-network/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt --isInit -c '{"function":"InitLedger","Args":[]}'
  • Troubleshoot errors using docker logs
    • Make sure to edit the docker-compose-test-net.yaml (see above) before starting the network
    • run docker ps to see the running containers
    • run docker logs <SERVER_NAME> in which SERVER_NAME is one of the container peer nodes
    • Watch out for non-deterministic code (e.g., random/time functions). This will cause validation to fail!
  • If you have errors from shutting down the network (e.g., "Device or resource busy"), then try restarting the Docker service

Developing and testing the application

  • Perform the same git procedures as the chaincode section above to pull code into your application-javascript directory, then cd to application-javascript
  • Run npm install or npm update if there are changes to the packages
  • Make sure the test network is running from the chaincode steps above
  • From the application-javascript directory, delete the wallet directory, and rerun node enrollAdmin.js, node registerUser.js or whatever init script you are using.
  • Now, run node app.js (or some other command)

Blockchain Explorer

https://github.com/hyperledger/blockchain-explorer (see the README instructions for bringing up the docker containers)

  • Make a directory fabric-blockchain-explorer in your home directory and follow the directions in the README, which include copying the following files over from the public repo:

wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/examples/net1/config.json
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/examples/net1/connection-profile/first-network.json -P connection-profile
wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/master/docker-compose.yaml
  • If using Windows and Ubuntu, open a Windows command prompt and type ubuntu config --default-user root to run the next shell as root
  • Make sure the hyperledger fabric test network is up, and then copy the organizations folder to the blockchain explorer
    • If the folder already exists, rm -rf organizations/
    • cp -rf ../fabric-samples/test-network/organizations/ .
    • You need the root permissions to copy over the secret keys of the running blockchain network.
  • No changes should be needed in docker-compose.yaml
  • Modify connection-profile/first-network.json as directed in the README instructions. Do a directory listing for the directory you just copied over: organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/. The name of the private key will be a 256 bit hash with a "_sk" suffix. Copy over this private key name. Edit the first-network.json file as follows:
  • Run docker-compose up -d
  • Navigate to http://locahost:8080
  • Use exploreradmin and exploreradminpw to login
  • Run docker-compose down -v when finished. Make sure to include the -v so the next time you bring up the server it pulls the correct data.
  • Now, you can revert to running as your own user account by running the following from the Windows command line: ubuntu config --default-user user_name