How to write your first smart contract for Hyperledger Fabric [Part 1/2]
#1
Since smart contracts can become quite complex, I will try to keep this as basic and simple as possible. In this tutorial, we will make simple account transfer balances, using smart contracts (logic.js file) on Hyperledger Fabric. To get started, it is assumed that you have Hyperledger Fabric/Composer up and running. If you need help with that, you can follow the instructions here.

Step 1: Navigate to the Composer Playground
Navigate to either IBM's hosted Composer Playground or if you have Hyperledger Fabric and Composer installed on your system, open your Terminal and run:
Code:
composer-playground

Now click "Deploy a new business network":
[Image: attachment.php?aid=60]

Step 2: Deploy the "Car Sales" Business Network File
Download the ".bna" file from here.

Select "Drop here to upload or browse" as shown below and select the .bna file that you downloaded in the last step:
[Image: attachment.php?aid=61]

Click deploy:
[Image: attachment.php?aid=62]

Step 3: Create the transaction file (smart contract):
Press "Add a file" as shown below:
[Image: attachment.php?aid=63]

Then press "Script File (.js)" then the "Add" button as shown below:
[Image: attachment.php?aid=64]

You will now see a "script.js" file.

Step 4: Link the smart contract to our model file
Now that our scripts.js file has been created, erase all text you currently see in the file. It should be blank. Here is a break down of how our setup of the script file should be:
[Image: attachment.php?aid=65]

So you may be wondering where the ".Sale" at the end of the parameter comes from. If you go into the model file, you will see a transaction named "Sale". That ".Sale" in the script.js file is merely linking the transaction to the one defined in the model file.
[Image: attachment.php?aid=66]

Note: The /** type syntax must be kept intact. If you have issues, copy and paste from here:
Code:
/**
* Move one asset to a different participant
* @param {org.tradesnetwork.Sale} sale - the car sale transaction
* @transaction
*/

Step 5: Writing the smart contract
Great! So now that we have everything setup let's begin with the smart contract. Start it off like this:
Code:
async function sale(contract){
}

As displayed in the picture below, the function name comes from the parameter we setup earlier. The argument name "contract" is not specific and can be named whatever you like:
[Image: attachment.php?aid=67]


Attached Files Thumbnail(s)
                               
Reply
#2
You still updating this?
Reply
#3
(06-25-2018, 08:42 AM)Sonisyll Wrote: You still updating this?
Yes. I haven't forgot about it, Big Grin I've just been very busy. I'm getting a microphone in the mail tomorrow and will also be working on an e-course and some new YouTube tutorials.
Reply
#4
Good to hear I see progress
Reply
#5
Part 1 is complete. Will start working on Part 2 next!
Reply