hyperledger Getting Started demo

    The official demo document Address:  preparation of the first application Hyperledger


 

  Preparation of matter:

  1. Download fabric-samples project, all application code in the document, hyperledger-the Samples

  2, the download hyperledger-samples docker mirror command official website provides :( need to install and docker npm curl and other tools)

     curl - ssl HTTP : // bit . LY / 2 ysbOFE | bash - S - 1.4 . 1 1.4 . 1 0.4 . 15 

  
The curl not visit this address, so I direct address test bash script to the local New bash file, and then executed directly, can be successful, but the speed is too slow to download files,    then download the file directly to the address into the browser window directly to the downloaded archive file, and then test to a virtual machine, and get the corresponding bin config file


   

     Extracting archive file, and get bin config directory, these two export directory to the path followed by the need to use these two folders command

    (Note: docker running after the current user or root user, may lead to export environment variables, or can not find the directory command)

    export PATH=<path to download location>/bin:$PATH

 


  After completion ready, you can begin to build hyperledger network, and interact with the application.

  Enter downloaded from github fabric-samples directory, go fabcar directory, execute the following command to start the network:

 

  sudo ./startFabric.sh javascript

 

  You can see the command for us to download the required network peer node, orderer ordering nodes, ca certificate authority nodes, etc., are on their own docker mirror, the download is successful, you should be able to display the following screen:

  

   After a successful open network, deploy applications, and perform network interaction, javascript way here used to deploy applications using npm tool.

  Into the fabric-samples directory fabcar / javascript directory, execute the following command:

  npm install

  Execution is complete, you can see the print out of the application directory:

  

 

   After starting the network and register the application, we began to register some users, these users are authenticated by their respective ca, and interact with the network:

  In fabcar / javascript directory, execute the following command, registering an administrator admin and a user user1:

  node enrollAdmin.js


  node registerUser.js

  

  

 

  We now have a hyperledger network, a network connection to the user's application and two, then we can operate by calling the corresponding smartcontract to ledger.

  First, try the following query operations, in fabcar / javascript directory, execute the following command,

  node query.js

 

   You can see all the information return:

 

   用 vim查看  query.js 文件中的代码,可以看到其实是通过调用对应 contract 的方法,查询返回所有的信息,对调用的方法进行细微修改,调用单个查询的方法

   

  可以看到,返回的是查询指定的单条记录结果:

  

 

   尝试了查询的操作后,再试着调用修改的方法。

  在同样的目录下,执行以下命令,向 ledger 中添加一条记录:

  

  node invoke.js

  

  执行完成后,可以看到提交的结果:

  

 

   此时,可以调用之前涉及到的查询方法,调用 query.js ,即可返回刚添加的目录信息。

  

  这个demo是在虚拟机环境下的ubuntu中运行的,运行结果和官方文档的结果一样,如果查阅文档的时候有遇到问题,欢迎一起探讨

  

  


 

Guess you like

Origin www.cnblogs.com/forwrader/p/10987953.html