Skip to Content

Step by Step process to create your first Blockchain Project – Hello World

Blockchain…!!! This might be one of the words which is buzzing around in SAP for a long time and many developers and consultants have been waiting to explore this opportunity.  SAP Blockchain as a Service, specifically Hyperledger Fabric is now made available in the cloud foundry trial account for development and testing activities.

Note: Trial accounts or services always comes with limitations.

In this blog, you will learn the following:

  1. Create SAP Cloud Foundry Trial Account
  2. Navigating to your Hypderledger Fabric account
  3. Creating a new instance
  4. Create & Deploy chaincode
  5. Create a Service Key
  6. Read/Write operations using Swagger
  7. Validate your read/write in Hyperledger Explorer

Before you begin, you may want to look at

and have your trail account active.

Once you understand Blockchain, it’s now time to get started with a small example “myfirstblock” in Hyperledger Fabric service.

1. Create SAP Cloud Foundry Trail Account

  • Login to trial account and click on Cloud Foundry trial

  • Select Europe (Frankfurt) and click on ok.

  • Your account should now be created and active for 29 days, click on Go to Space

 

 

2. Navigating to your Hypderledger Fabric account

  • Click on Services and Service Marketplace

  • In the list of services, search for Hyperledger Fabric and click on it

  • Hyperledger Fabric – Overview with all the documentation, support information, and services plan should be listed.

3. Creating a new instance

  • Click on Instances and then click on New Instance.

  • Select Plan dev-beta and click on next(Dev-Beta was active for a limited period and no more active. Request you to select Dev, ignore the error message on pricing and continue with the same steps)

  • Click next on Specify Parameters (optional) and Assign Application (optional). In the confirm, enter “myfirstinstance” and click on Finish

  • The new instance should be created with an option such as Dashboard and Delete Instance under actions. Click on Open Dashboard

  • A new tab opens up, enter your login details; same which was used during your cloud platform registration. Note: Do not use P-Number.

This is a dashboard where you can understand the Node, Peer Status, Fabric Version, Network and Create Channels.

  • Now click on Channels, then click on Create Channels and enter the following details. To know more about the channels, please use the hyperlink above.

  • Click on Create New Instance for the channel which was just created

  • Do not modify the Service Instance name, click on Create.

  • Open the service Instance Channel

4. Create & Deploy a chaincode

  • Click on Deploy Code and select the “sample web.zip”.  The sample code has been shared on the link, however, to make it easy I have attached the sample code to this link. Below are the files which I have zipped as a package.

  • Drag & Drop or Choose the sample web.zip file.

  • Click on Deploy and you should be able to see the success message as below

  • Click on “Test Chaincode” and a new window opens which is known as swagger.

5. Create a Service Key

  • Go back the window Hyperledger Fabric Dashboard and click on Overview and enter the following details under “Service Keys” and click on Create Key

  • Expand the key and copy the “clientId” and “clientSecret” which is required for authorization in Swagger

 

6. Read/Write operations using Swagger

  • Go to Swagger tab and click on Authorize button and enter the clientId, clientSecret and authorize

Once its authorized, close the window.

  • Now that we have the authorization and we are doing the first transaction to the block, we will try a POST operation, click on the POST and then click on Try it out. Enter the details as shown below and click on execute.

  • You should now be able to see the response 201 as shown below

There you go, you have now successfully made your first POST operation to the blockchain.

  • Now let us try to read the same data which was written to the block. Click on Get and then click on Try it out. Enter the ID “101” was used in POST operation and click on execute. You should be able to see the response as shown below.

 

7. Validate your read/write in Hyperledger Explorer

  • To validate the same in a Blockchain, we use the Hyperledger Fabric Explorer. Shift to the other tab “Hyperledger Fabric Dashboard” and click on Explorer.

Here you can identify that we have totally 3 blocks created, 0 is the Genesis Block, 1 is the Chaincode deployed by us and 2 is the successful transaction from swagger.

  • Click on block 2 to get the details

Alright, it’s now time to congratulate you J

#HappyLearning…!!!

Regards,

Nagesh

 

 

30 Comments
You must be Logged on to comment or reply to a post.
    • Hi Nagesh,

      sorry to hear that the program is now closed. for those who, who are not gui beholden, there is always the open source route available with a little bit of community support, but again it’s outside of SAP ecosystem.

      thank you, gm

  • Hi,

    When I am trying to deploy the chaincode with package structure exactly as instructed by you, I am getting error-

    File chaincode.yaml not found. Please make sure that the provided ZIP archive has the chaincode.yaml as well as the src directory located at the root level of the archive.

     

    However, when I try to deploy the zipped package provided by you, it works.

    Could you please help with this?

     

    Thanks

    • Hi Prajakta,

      Please ensure the files are structured and saved as in the zip file which I have shared. In case you are copying the code from the help website, ensure the code & file names are accurate. No additional changes were made, so it should work  🙂

      Regards,

      Nagesh

      • Hi Nagesh,

        Thanks for your response.

        Firstly I deployed the zipped package provided by you on my channel.

        Then, I extracted the code and just changed version in chaincode.yaml file from 13 to 14. Afterwards, I zipped again and tried to deploy using upgrade chaincode. However, it is still showing me the same error-

        File chaincode.yaml not found. Please make sure that the provided ZIP archive has the chaincode.yaml as well as the src directory located at the root level of the archive.

        There is no change in structure of files or naming.

        Can’t ascertain the reason behind this error.

         

        Thanks

         

        • Do you mind sharing which IDE or editor you used for editing .yaml file? It seems SCP is unable to read the chaincode.yaml file whose format may haave changed on my system. I am using Notepad++ and MS Visual Studio..

           

          Thanks

          • Hi Prajakta,

            I am using Atom Editor, it works for both GoLang and YAML files and follow the folder structure, it should work good.

            Regards,

            Nagesh

             

          • Thanks Nagesh.

            Really value your responses.

            I installed Atom editor and created folder structure as given in development guide. Still, same issue is coming. Is there a possibility that you are using a different compression technique to create zip file? I am creating zip using Windows default- Send to compressed folder option.

            Regards,

            Prajakta

             

             

          • Hi Gregory,

            Thanks for your response.

            I have created zip file with exact folder structure as given in Development guide.

            It seems the chaincode.yaml file is getting corrupted while compression.

            Regards,

            Prajakta

  • Very nice blog, thank you Nagesh

     

    Can you please explain how can i create a SAP Cloud Platform destination on top of this blockchain service in order to get access from SAPUI5 ?

     

    Best regards

    • Hi Guillaume,

      For UI5, we can use SAP Neo account, blockchain APIs can be used for this and UI5 program can be developed using WEBIDE and deployed in Neo.

      Regards,

      Nagesh

       

      • Hi Nagesh

         

        As far as i understand, this blockchain api uses OAuth2ClientCredentials authentication.

        I can create a destination on cloud foundry but no webIde is available.

         

        Can you please guide me how to create this destination on neo ?

         

        Regards

        Guillaume

  • Thanks for the blog Nagesh,

     

    i can’t access my space in my subaccount. It keeps loading… Do I have to give permission or something else?

     

    Regards,

    Talha Demirci

    • Hi Talha,

       

      If its Trial, no additional permission are required. Try to clear the cookies and try again. It should work.

      Regards,

      Nagesh

       

    • Excellent, you may take a look at the latest release and plan your developments. SAP also provides options to call APIs from ECC and HANA Systems.

      If you have any specific PoC or Project requirements, let us know we can discuss about it.

      Regards,

      Nagesh

       

       

        • Hi Siva,

          Below link should be helpful to you then: https://help.sap.com/viewer/c5bee9180afc4a4e93a0742bb352db11/1.0/en-US/3d17b9c2c38841cd8c56c91342aee048.html

          We can further connect on email as required.

          Regards,

          Nagesh

  • Hi,

    I am stuck at one step .

    I had coped the Authkey, and later you mentioned to “Go to the swagger tab and click on AUthorization” where is this swagger tab , can you please tell me

        • Two things I have to ask

          1. I have being using Neo trail account and using IOT service to build few POC and Demos( running successful thanks for many blogs on this topic ) , Is it possible to enable IOT service in cloud foundry account as well ?  so that I can merge this two – IOT to gather data and Block chain to store data changes ( like any change should trigger as a prof for medic. – again just a poc )
          2. Is there any way to connect the to Hana DB ? tho I did not find the DB in cloud foundry.

           

  • I ran the Hello World test chain code and got Code 200 with a description of “OK” for the GET operation and “Text Written” for the POST operation. In your write-up, you show code 201. Are either of these correct? Also, after each operation, I’m also seeing a Code of 500 with a description of “Failed”. What does this mean? Is there any place one can find the definitions of all these codes?

    Also, after running both POST and GET, when reviewing the blocks in the Explore window, it appears that only the Writes have content and the Reads are empty. According to your write-up, I should be seeing both. What does this signify?

  • For who couldn’t find the hyperledger fabric service in your cloud foundary service marketplace,

    please go to the entitlement tab and edit to enable “application runtime, hyperledger fabric (dev, channel)

  • Hello Nagesh,

    Thanks for the article, it is great. Is that possible to deploy chain code written in NODE JS in SAP Blockchain platform ? or It will only take GO language ?

    Please advice, thank you.

    Best wishes,

    Bhanu Kandregula