Playground Tutorial
In this step by step tutorial we'll walk through setting up a business network, defining our assets,
participants and transactions, and testing our network by creating some participants and an asset, and
submitting transactions to change the ownership of the asset from one to another. This tutorial is
intended to act as an introduction to IBM Blockchain Platform: Develop concepts using the online
playground environment.
We are going to build a Perishable Goods Network from scratch. The example business network will
show growers, shippers and importers defining contracts for the price of perishable goods, based on
temperature readings received for shipping containers.
The business network defines a contract between growers and importers. The contract stipulates that:
On receipt of the shipment the importer pays the grower the unit price x the number of units in the
shipment. Shipments that arrive late are free. Shipments that have breached the low temperate
threshold have a penalty applied proportional to the magnitude of the breach x a penalty factor.
Shipments that have breached the high temperate threshold have a penalty applied proportional to
the magnitude of the breach x a penalty factor.
This business network defines:
Participants Grower Importer Shipper
Assets Contract Shipment
Transactions TemperatureReading ShipmentReceived SetupDemo
Note: Answer the questions as you follow along the instructions below
Step One: Open the IBM Blockchain Platform: Develop Playground
Open Blockchain Platform Playground. You should see the My Business Networks screen. The My
Business Networks page shows you a summary of the business networks you can connect to, and the
identities you can use to connect to them. Don't worry about this too much for the time being, as
we're going to create our own network.
Step Two: Creating a new business network
Next, we want to create a new business network from scratch. A business network has a couple of
defining properties; a name, and an optional description. You can also choose to base a new business
network on an existing template, or import your own template.
1. Click Deploy a new business network under the Web Browser heading to get started.
2. The new business network needs a name, let's call it tutorial-network.
3. Optionally, you can enter a description for your business network.
4. Next we must select a business network to base ours on, because we want to build the
network from scratch, click empty-business-network.
5. Now that our network is defined, click Deploy.
NOTE: You can refer to the Video Demo available online.
Step Three: Connecting to the business network
Now that we've created and deployed the business network, you should see a new business network
card called admin for our business network tutorial-network in your wallet. The wallet can contain
business network cards to connect to multiple deployed business networks.
When connecting to an external blockchain, business network cards represent everything necessary
to connect to a business network. They include connection details, authentication material, and
metadata.
To connect to our business network click Connect now under our business network card.
Question 1:
How many files are there under the ‘FILES’ heading on the left-hand panel of the webpage? Name
them.
Step Four: Adding a model file
As you can see, we're in the Define tab right now (top banner of webpage), this tab is where you
create and edit the files that make up a business network definition, before deploying them and
testing them using the Test tab.
As we selected an empty business network template, we need to modify the template files provided.
The first step is to update the model file. Model files define the assets, participants, transactions, and
events in our business network.
1. Click the Model file to view it.
2. Delete the lines of code in the model file and replace it with this.
Question 2:
Read the lines mentioned in the Model file and list the items mentioned inside:
enum ProductType {
…….
Step Five: Adding a transaction processor script file
Now that the domain model has been defined, we can define the transaction logic for the business
network. Composer expresses the logic for a business network using JavaScript functions. These
functions are automatically executed when a transaction is submitted for processing.
1. Click the Add a file button.
2. Click the Script file and click Add.
3. Delete the lines of code in the script file and replace it with the code here.
NOTE: You can refer to the Video Demo available online for this step.
Step Six: Access control
Access control files define the access control rules for business networks.
1. Click the Access Control to view it.
2. Delete the lines of code in the access file and replace it with this.
Question 3:
After the above step, how many files are present now under the ‘FILES’ heading on the left-hand
corner of the webpage? Name them.
Step Seven: Deploying the updated business network
Now that we have model, script, and access control files, we need to deploy and test our business
network. Click Deploy changes to upgrade the business network.
Step Eight: Testing the business network definition
To test this Business Network Definition in the Test tab, click the Test tab to get started.
(NOTE: You can refer to the Video Demo for how to navigate to Test.)
Question 4:
Name the various files under the PARTICIPANTS and ASSETS headings on the left panel of the
webpage. Do they have any content or are they empty?
Now let’s do some transactions:
Submit a SetupDemo transaction by clicking Submit Transaction and replace the lines of code
with:
{
"$class": "org.acme.shipping.perishable.SetupDemo"
}
This transaction populates the Participant Registries with a Grower , an Importer and a Shipper .
The Asset Registries will have a Contract asset and a Shipment asset.
Question 5:
a) Read the details from the newly created ‘participants’ of GROWER, IMPORTER and SHIPPER,
and state each one’s country and account balance
b) Read the details from the SHIPMENT and state the type, status and unitCount. Take a snapshot
of the SHIPMENT details
Submit a TemperatureReading transaction by clicking Submit Transaction again and replace
the lines of code with:
{
"$class": "org.acme.shipping.perishable.TemperatureReading",
"centigrade": 8,
"shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
}
The transaction can be viewed under the ‘TRANSACTIONS’ on the left panel. If the temperature
reading falls outside the min/max range of the contract, the price received by the grower will be
reduced. You may submit several readings if you wish. Each reading will be aggregated
within SHIP_001 Shipment Asset Registry.
Question 6:
Go back to the SHIPMENT and look for the updates. Attach a screenshot of ‘SHIP_001’
Submit a ShipmentReceived transaction for SHIP_001 to trigger the payout to the grower,
based on the parameters of the CON_001 contract. Click Submit Transaction and replace the
lines of code with:
{
"$class": "org.acme.shipping.perishable.ShipmentReceived",
"shipment": "resource:org.acme.shipping.perishable.Shipment#SHIP_001"
}
If the date-time of the ShipmentReceived transaction is after
the arrivalDateTime on CON_001 then the grower will no receive any payment for the shipment.
Question 7:
Read the details from the newly created ‘participants’ of GROWER, IMPORTER and SHIPPER,
and state each one’s country and account balance.
Step Nine: Try it out yourself!
In this step, you can try to tinker with different inputs, deploy it and observe how it all works. To do
this, we need to test our business network by creating some participants and assets, and then using
transaction to deploy changes.
1. Ensure that you have the Grower tab selected on the left and click Create New Participant in
the upper right.
2. What you can see is the data structure of a Grower participant. You can modify the country
and accountBalance of the Grower.
3. Click Create New to create the participant.
4. You should be able to see the new Grower participant you've created. We need
another Grower to test our transaction though, so create another Grower.
5. Select the Importer tab and click Create New Participant in the upper right. Create several
Importer participants. You can modify the country and accountBalance of the Importer.
6. Select the Shipper tab and click Create New Participant in the upper right. Create several
Shipper participants. You can modify the country and accountBalance of the Shipper.
7. Select the Contract tab and click Create New Asset in the upper right. Create several Contract
assets. You can modify the unitPrice, minTemperature etc. to design your contract.
8. Select the Shipment tab and click Create New Asset in the upper right. Create several
Shipment assets. You can modify the unitCount, contract etc. to design your shipment.
9. You can observer how things have changed by expanding the data section for the participants
and assets.
NOTE: You can refer to the Video Demo available online for how to create participants and assets.
Note that there are some differences in the demo due to the different network built.
For more details click this link.