-
Notifications
You must be signed in to change notification settings - Fork 4
Hyperledger Fabric Development README
pdhuff edited this page Nov 17, 2020
·
6 revisions
- Install the fabric samples and binaries for the test network (https://hyperledger-fabric.readthedocs.io/en/release-2.2/install.html)
curl -sSL https://bit.ly/2ysbOFE | bash -sexport PATH=/home/<USER>/fabric-samples/bin:$PATH
-
cd to fabric-samples/test-network and make sure you clear any previously running networks (https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html)
./network.sh down
-
Fully bring up the test network (https://hyperledger-fabric.readthedocs.io/en/release-2.2/write_first_app.html)
./network.sh up createChannel -c mychannel -ca
- 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=trueon lines 77 and 115 (approximately). This will allow nodejs errors to become visible in docker logs
- Add
- 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 psto 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
- 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 installornpm updateif there are changes to the packages - Make sure the test network is running from the chaincode steps above
- From the
application-javascriptdirectory, delete the wallet directory, and rerunnode enrollAdmin.js,node registerUser.jsor whatever init script you are using. - Now, run
node app.js(or some other command)
https://github.com/hyperledger/blockchain-explorer (see the README instructions for bringing up the docker containers)
- Make a directory
fabric-blockchain-explorerin 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 rootto 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.
- If the folder already exists,
- No changes should be needed in
docker-compose.yaml - Modify
connection-profile/first-network.jsonas 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:- On line 41, paste in the secret key name to the path /tmp/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/$PRIVATE_KEY_YOU_JUST_COPIED
- On line 45, replace Admin@org1.example.com-cert.pem with cert.pem. The path should look like: /tmp/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/cert.pem
- Run
docker-compose up -d - Navigate to http://locahost:8080
- Use exploreradmin and exploreradminpw to login
- Run
docker-compose down -vwhen finished. Make sure to include the-vso 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