BLCN532 Lab 2 Writing Chaincode
BLCN532 Lab 2 Writing Chaincode
Writing chaincode
V2.0
Introduction
Now that you have a running business network, you can write, install, and run smart contracts, called
chaincode, to interacts with your blockchain. Chancode makes up your blockchain application and
provides the only way for users to read from, and append to, the blockchain.
In this lab you’ll examine several chaincode files, run the sample chaincode presented in your textbook,
and run tests on the chaincode to assess its functionality.
Lab Deliverables:
To complete this lab, you must create a Lab Report file and submit the file in iLearn. The Lab Report file
must be a Microsoft Word format (.docx), and have the filename with the following format:
BLCN532_SECTION_STUDENTID_LASTNAME_FIRSTNAME_Lab02.docx
To get started, create a Microsoft Word document (.docx) with the correct filename for this lab. You’ll
be asked to enter text and paste screenshots into the lab report file.
NOTE: All screenshots MUST be readable. Use the Ubuntu Screen Capture utility (see the lab video.)
Make sure that you label each screenshot (i.e. Step 2.1.3) and provide screenshots in order. For
commands that produce lots of output, I only want to see the last full screen when the command
finishes. Provide FULL screenshots, NOT cropped images.
SECTION 1: Running chaincode
First, you’ll start your sample business network in development mode (note the ‘-d’ option).
1. Open PowerShell
2. PS %HOME%> cd vagrant\hyperledger
3. PS %HOME%\vagrant\Hyperledger> vagrant up
4. Login to your Linux VM (userid: vagrant password: vagrant) and open a Terminal window.
5. $ cd $GOPATH/src/trade-finance-logistics/network
6. $ ./trade.sh up -d true
7. $ date
8. Create a screenshot of the results of steps 5 - 7 and paste it into your Lab Report File.
Next, you’ll use a different PuTTY connection to compile and run the chaincode.
NOTE: This is the SECOND Terminal CONNECTION for screenshots in later steps.
2. $ cd $GOPATH/src/trade-finance-logistics/network
3. $ docker exec -it chaincode bash
4. # cd trade_workflow_v1 (Note the new prompt)
5. # go build
1. # export CORE_PEER_ADDRESS=peer:7052
2. # export CORE_CHAINCODE_ID_NAME=tw:0
3. # ./trade_workflow_v1 (This is a server process, so you won’t get a prompt back.)
NOTE: the command in step 7 doesn’t copy-paste well. You’ll just have to type it.
8. Create a screenshot (in the current Terminal window) of the results of step 7 and paste it into
your Lab Report File.
9. # peer chaincode invoke -n tw -c '{"Args": ["getTradeStatus","trade-12"]}' -C tradechannel
10. Create a screenshot (in the current Terminal window) of the results of step 9 and paste it into
your Lab Report File.
11. In the SECOND Terminal window (the one you opened in step 1.2), create a screenshot of the
results of step 9 and paste that screenshot into your Lab Report File.
Step 2.1:
1. $ cd $GOPATH/src/trade-finance-logistics/chaincode/src/github.com/trade_workflow_v1
2. nano tradeWorkflow_test.go
3. Find the method that tests ShipmentInitiation.
4. Create a screenshot (in the current Terminal window) that shows the other methods (should be
7) the current method invokes to test its functionality. (You can find this information in a
program comment. Comments start with two forward slashes. Look for lines that start with
“//”.) Paste that screenshot into your Lab Report File.
5. Exit nano
6. $ go test
7. $ date
8. Create a screenshot (in the current Terminal window) of the results of steps 6 and 7 and paste
that screenshot into your Lab Report File.
Section 4: Wrapping up
Now that you have compiled, installed, run, and tested your chaincode, you need to properly shutdown
your business network.
You should have 10 screenshots in your Lab Report File. Save your file and submit it in iLearn as a file
attachment for the Lab 2 assignment.