<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Julia Shu on Medium]]></title>
        <description><![CDATA[Stories by Julia Shu on Medium]]></description>
        <link>https://medium.com/@jushuspace?source=rss-e34529b56239------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NX8pOgokpxqjij7UafiYig.jpeg</url>
            <title>Stories by Julia Shu on Medium</title>
            <link>https://medium.com/@jushuspace?source=rss-e34529b56239------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:48:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jushuspace/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hyperledger Fabric Monitoring with Prometheus and StatsD]]></title>
            <link>https://medium.com/@jushuspace/hyperledger-fabric-monitoring-with-prometheus-and-statsd-f43ef0ab110e?source=rss-e34529b56239------2</link>
            <guid isPermaLink="false">https://medium.com/p/f43ef0ab110e</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[statsd]]></category>
            <category><![CDATA[hyperledger]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[graphite]]></category>
            <dc:creator><![CDATA[Julia Shu]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 13:06:17 GMT</pubDate>
            <atom:updated>2019-05-27T11:10:37.883Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Q_oo6dAjdyb-AC9su6F9w.png" /></figure><p>In the previous <a href="https://medium.com/@jushuspace/hyperledger-fabric-operations-service-tutorial-7a845257368d">article</a> we’ve configured Hyperledger fabric’s Operations Service. Now it’s time to visualize our data to provide a better understanding.</p><p>Let’s take a look at how to configure <em>byfn</em> to be able to monitor metrics with Prometheus.</p><p>Download the latest version of Prometheus and extract it to a separate folder:</p><blockquote>$ curl -LO <a href="https://github.com/prometheus/prometheus/releases/download/v2.7.1/prometheus-2.7.1.linux-amd64.tar.gz">https://github.com/prometheus/prometheus/releases/download/v2.7.1/prometheus-2.7.1.linux-amd64.tar.gz</a> &amp;&amp; tar -xvzf prometheus-2.7.1.linux-amd64.tar.gz</blockquote><p>In prometheus folder you will find <em>prometheus.yml</em> file.</p><p>Configure it to scrape Hyperledger metrics: add <em>job_name</em> and <em>targets</em> to the scrape_configs section.</p><p>The file configuration should look as follows:</p><pre>global:<br>  scrape_interval: 15s<br>  evaluation_interval: 15s<br>scrape_configs:<br>  - job_name: ‘prometheus’<br>    scrape_interval: 10s<br>    static_configs:<br>    - targets: [‘localhost:9090’]<br>  - job_name: ‘hyperledger_metrics’<br>    scrape_interval: 10s<br>    static_configs:<br>      - targets: [‘peer0.org1.example.com:9443’, ‘peer1.org1.example.com:9443’, ‘peer0.org2.example.com:9443’, ‘peer1.org2.example.com:9443’, ‘orderer.example.com:9443’]</pre><p>After that, we are ready to run prometheus on docker:</p><pre>$ sudo docker run -d --name prometheus-server -p 9090:9090 \<br>  --restart always \<br>  -v /home/mccdev/prometheus/prometheus/prometheus.yml:/prometheus.yml \<br>  prom/prometheus \<br>  --config.file=/prometheus.yml</pre><p>Notice that since docker always launches containers in a special network, named bridge (unless we tell it otherwise), we will have to join prometheus container to our fabric network:</p><blockquote>$ docker inspect peer1.org1.example.com</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I9f67kfW-6mXEBFLjO8aqg.png" /></figure><blockquote>$ sudo docker network connect net_byfn 5b8cbf9d8fa6</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZKLOSN9OyGbe5Gc_TZLng.png" /></figure><p>We can access statistics at:</p><p>http://localhost:9090/</p><p>To check whether peer metrics were successfully scrapped, enter <em>scrape_samples_scraped</em> and look at the appeared table.</p><p>The values of the elements should not be zero.</p><p>If so, you can start exploring your metrics, otherwise, check the configuration once again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NcjRT9S7bEQmLNlVKfuIvw.png" /></figure><p>Now, that we have successfully dealt with Prometheus, it’s StatsD turn (remember that there are two ways to get metrics: Prometheus and StatsD).</p><p>The installation process is quite similar to Prometheus.</p><p>First of all, we need to get docker image for Graphite and StatsD, which could be found <a href="https://github.com/graphite-project/docker-graphite-statsd">here</a>.</p><p>Then, we should start graphite container:</p><pre>$ docker run -d\<br> --name graphite\<br> --restart=always\<br> -p 80:80\<br> -p 2003-2004:2003-2004\<br> -p 2023-2024:2023-2024\<br> -p 8125:8125/udp\<br> -p 8126:8126\<br> graphiteapp/graphite-statsd</pre><p>Now it’s time to change docker file (<em>docker-compose-base.yaml</em>) configuration.</p><p>Each peer should contain the following environment variables:</p><pre>CORE_OPERATIONS_LISTENADDRESS<br>CORE_METRICS_PROVIDER<br>CORE_METRICS_STATSD_ADDRESS<br>CORE_METRICS_STATSD_NETWORK<br>CORE_METRICS_STATSD_PREFIX</pre><p>We should also make sure to specify port <em>8125</em>.</p><p>Peer configuration example:</p><pre>peer0.org1.example.com:<br>  container_name: peer0.org1.example.com<br>  extends:<br>   file: peer-base.yaml<br>   service: peer-base<br>  environment:<br>   - CORE_PEER_ID=peer0.org1.example.com<br>   - CORE_PEER_ADDRESS=peer0.org1.example.com:7051<br>   - CORE_PEER_GOSSIP_BOOTSTRAP=peer1.org1.example.com:7051<br>   - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051<br>   - CORE_PEER_LOCALMSPID=Org1MSP<br>   # metrics<br>   - CORE_OPERATIONS_LISTENADDRESS=peer0.org1.example.com:8125<br>   - CORE_METRICS_PROVIDER=statsd<br>   - CORE_METRICS_STATSD_ADDRESS=graphite:8125<br>   - CORE_METRICS_STATSD_NETWORK=udp<br>   - CORE_METRICS_STATSD_PREFIX=PEER_01<br>  volumes:<br>     - /var/run/:/host/var/run/<br>     - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp<br>     - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls<br>     - peer0.org1.example.com:/var/hyperledger/production<br>  ports:<br>   - 7051:7051<br>   - 7053:7053<br>   - 8125:8125</pre><p>Remember to pay attention to the ports you use: for <em>peer0</em> the ports will be <em>8125:8125</em>,for <em>peer1</em> we will use <em>9125:8125</em>, and so on.</p><p>Orderer can be configured as follows:</p><pre>- ORDERER_OPERATIONS_LISTENADDRESS=orderer.example.com:8125<br>- ORDERER_METRICS_PROVIDER=statsd<br>- ORDERER_METRICS_STATSD_ADDRESS=graphite:8125<br>- ORDERER_METRICS_STATSD_NETWORK=udp<br>- ORDERER_METRICS_STATSD_PREFIX=ORDERER</pre><pre>ports:<br>   - 7125:8125</pre><p>Let’s launch our byfn.</p><p>Remember to join graphite container to byfn network, otherwise you will fail to successfully launch it and get an error:</p><blockquote>Error: error getting endorser client for channel: endorser client failed to connect to peer0.org1.example.com:7051: failed to create new connection: context deadline exceeded</blockquote><p>And the peer container logs will show that graphite was not found in our network:</p><blockquote>Error: failed to initialize operations subystems: dial udp: lookup graphite on 127.0.0.11:53: no such host</blockquote><p>To connect container to the network use the following command:</p><blockquote>$ sudo docker network connect net_byfn graphite</blockquote><p>If everythig was done correctly, you will see available metrics at</p><blockquote>http://localhost/metrics/index.json</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*FnLGU3ORlLfEMtJEZ2X6gg.png" /></figure><p>And to visualize the data go to</p><blockquote>http://localhost/</blockquote><p>and choose the desired metrics to be displayed on the graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7aLhTzT0Mm_PdkqzNwT9Q.png" /></figure><p>That’s it! Hope, this tutorial was helpful for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f43ef0ab110e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger Fabric Operations Service Tutorial]]></title>
            <link>https://medium.com/@jushuspace/hyperledger-fabric-operations-service-tutorial-7a845257368d?source=rss-e34529b56239------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a845257368d</guid>
            <category><![CDATA[restful-api]]></category>
            <category><![CDATA[hyperledger-fabric]]></category>
            <category><![CDATA[hyperledger]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Julia Shu]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 12:47:14 GMT</pubDate>
            <atom:updated>2019-05-27T11:06:18.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffCRwsax2FeIK_hlsjnhLA.png" /></figure><p>Hyperledger Fabric v1.4 provides the following features for monitoring peer and orderer nodes:</p><ol><li>Log Level Management [/logspec]</li><li>Health Check [/healthz]</li><li>Metrics [/metrics]</li></ol><p>Configuring the Operations Services is not a rocket science but it might get a little bit tricky if you miss just one little detail.</p><p>So, here’s an example on how to configure operations services in BYFN network.</p><p>According to the <a href="https://hyperledger-fabric.readthedocs.io/en/release-1.4/operations_service.html">official documentation</a> we need to modify Operations section in <em>core.yaml</em> file and specify <em>listenAddress</em> and <em>TLS</em> configurations (for now, you can just leave tls disabled).</p><blockquote>$ vi ~/fabric-samples/config/core.yaml</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*filqRMCUvhODOtPD42GI6g.png" /></figure><p>After doing so, let’s launch BYFN network and try to access log level.</p><blockquote>$ cd ~/fabric-samples/first-network</blockquote><blockquote>$ ./byfn.sh -m up</blockquote><blockquote>$ docker exec -it cli bash</blockquote><blockquote># curl peer0.org1.example.com:9443/logspec</blockquote><p>Unfortunately, <em>curl</em> command will result in the following error:</p><blockquote>curl: (7) Failed to connect to peer0.org1.example.com port 9443: Connection refused</blockquote><p>Lets try to understand what happened here.</p><p>The very first thing to do is to check our configuration for operations.</p><blockquote># vi /etc/hyperledger/fabric/core.yaml</blockquote><p>As you remember, we’ve used 127.0.0.1 for <em>listenAddress </em>which implies that we can not access external IP.</p><p>Let’s double check it by conducting necessary operations inside the <em>peer</em> container. This time we will use <em>wget</em> as <em>curl</em> is not installed in the container.</p><blockquote>$ docker exec -it peer0.org1.example.com bash</blockquote><blockquote># wget peer0.org1.example.com:9443/logspec</blockquote><p>As expected, the error message appears:</p><blockquote>Connecting to peer0.org1.example.com (peer0.org1.example.com)… failed: Connection refused</blockquote><p>But we will succeed if we use 127.0.0.1 address.</p><blockquote># wget 127.0.0.1:9443/logspec</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*UUEoZHKAqnJSeanayI1B9g.png" /></figure><p>Which proves that we need to set up operations listening address.</p><p>To do so, modify the <em>docker-compose</em> file again by specifying CORE_OPERATIONS_LISTENADDRESS for <strong>each</strong> peer.</p><blockquote><em>$ vi ~/fabric-samples/first-network/base/docker-compose-base.yaml</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*FXtYjFO4678ERV1gpWHdLQ.png" /></figure><p>Now let’s try sending GET /logspec request again.</p><p>(Don’t forget to restart the BYFN network before doing so).</p><blockquote>$ docker exec -it cli bash</blockquote><blockquote># curl peer0.org1.example.com:9443/logspec</blockquote><p>The output will be as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t_JJ8kOWgyTBm499x9zqPQ.png" /></figure><p>In a similar way, we can perform health check:</p><blockquote># curl peer1.org1.example.com:9443/healthz</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*Z081UJWPTpehiF7URtvtXg.png" /></figure><p>Finally, lets configure metrics by adding <em>CORE_METRICS_PROVIDER=prometheus</em> for <strong>each</strong> peer in <em>docker-compose-base.yaml</em> file and denoting prometheus metrics provider in core.yaml under <em>Metrics</em> <em>section</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*Z0Yf8XcfK1aBDWGDus73Iw.png" /></figure><p>If everything was configured well, you will see a list of metrics after performing the following command in cli container:</p><blockquote># curl peer1.org1.example.com:9443/metrics</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c7t746L_SAmINLpfNnkZqA.png" /></figure><p>Your <a href="https://medium.com/@jushuspace/hyperledger-fabric-monitoring-with-prometheus-and-statsd-f43ef0ab110e">next step</a> might be to configure prometheus to display data in a more human-friendly way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a845257368d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyperledger Fabric Event Listener Tutorial]]></title>
            <link>https://medium.com/@jushuspace/hyperledger-fabric-event-listener-tutorial-2484614a9e4?source=rss-e34529b56239------2</link>
            <guid isPermaLink="false">https://medium.com/p/2484614a9e4</guid>
            <category><![CDATA[chaincode]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[event-listener]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[hyperledger]]></category>
            <dc:creator><![CDATA[Julia Shu]]></dc:creator>
            <pubDate>Wed, 13 Feb 2019 13:43:18 GMT</pubDate>
            <atom:updated>2020-06-12T17:28:25.160Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BagyCU9o-qRDpKcxpXsLhQ.png" /></figure><p>In my opinion, tutorial is quite a tricky thing to do because it somehow would make you become lazy and unchallenged — since you could just look up how other people successfully did something and you only need to follow all the instructions, then voila! You did it.</p><p>But on the bright side, tutorials are very helpful. It could save a lot of your time trying to figure out some coding and it’s also good as a learning process (that’s not painful one).</p><p>The purpose of this tutorial is to provide instructions on how to launch event client.</p><p>At first glance, this tutorial might seem a little complicated; but after reading through it, I hope it could be helpful and wouldn’t be as hard anymore.</p><p>At the end of this tutorial, I will list all possible errors that you might encounter and how to fix them.</p><p><strong>Events client source code</strong> modified in this tutorial can be found <a href="https://github.com/hyperledger/fabric/tree/release-1.4/examples/events/eventsclient">here</a>.</p><p>And for the demonstration, I will use <strong>Building Your First Network (BYFN)</strong> Fabric sample network.</p><p>At first, I wasn’t sure whether I should include BYFN launching steps, because these steps are quite easy and it could be found in the official documentation and other tutorials. But then again, there must be some people who’re not familiar with these steps, so I thought why not put it here.</p><p>If you are a beginner, <em>Step 0</em> will save your time looking for the right commands to run in your terminal and if you are an expert, you can just skip <em>Step 0</em>.</p><h3><strong>Step 0</strong></h3><p>Navigate to the first-network folder inside fabric-samples.</p><pre>$ cd fabric-samples/first-network</pre><p>Start the network with</p><pre>$ ./byfn.sh -m up</pre><p>Once everything is done bash into cli container.</p><pre>$ docker exec -it cli bash</pre><h3><strong>Step 1</strong></h3><p>As BYFN already has chaincode — <em>mycc</em> pre-installed, let’s just upgrade it to see the event message from LSCC (Lifecycle System Chaincode) chaincode.</p><pre>export CHAINCODE_NAME=mycc</pre><pre>peer chaincode install -n $CHAINCODE_NAME -v 1.1 -p github.com/chaincode/chaincode_example02/go/</pre><pre>peer chaincode upgrade -C mychannel -n $CHAINCODE_NAME -v 1.1 -c &#39;{&quot;Args&quot;:[&quot;init&quot;,&quot;a&quot;,&quot;100&quot;,&quot;b&quot;,&quot;200&quot;]}&#39; -o orderer.example.com:7050 — tls true — cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -P &#39;AND (&#39;\&#39;&#39;Org1MSP.peer&#39;\&#39;&#39;,&#39;\&#39;&#39;Org2MSP.peer&#39;\&#39;&#39;)&#39;</pre><p>Note that if you want to send events from your chaincode, you need to insert the following code fragment into your chaincode:</p><pre>err := stub.SetEvent(&quot;EventID&quot;, []byte(&quot;Event Message&quot;))<br>if err != nil {<br>return shim.Error(err.Error())<br>}</pre><h3><strong>Step 2</strong></h3><p>Now let’s edit <a href="https://github.com/hyperledger/fabric/tree/release-1.4/examples/events/eventsclient"><em>eventsclient.go</em></a> file</p><p><em>ROOT</em> must contain the name of the channel configuration file — for BYFN, the file name is configtx.yaml file.</p><pre>const (<br>OLDEST = -2<br>NEWEST = -1</pre><pre><strong>ROOT = &quot;configtx&quot;</strong>)</pre><p>Scroll to <em>readCLInputs()</em> function and specify necessary parameters.</p><p>Start with peer name.</p><pre>flag.StringVar(&amp;serverAddr, &quot;server&quot;, &quot;<strong>peer0.org1.example.com:7051&quot;</strong>, &quot;The RPC server to connect to.&quot;)</pre><p>Do not forget to add an entry into <em>/etc/hosts</em> file.</p><pre>$ echo &quot;<strong>ip_address peer0.org1.example.com&quot;</strong> | sudo tee -a /etc/hosts</pre><p>Specify your channel from which you want to receive events.</p><pre>flag.StringVar(&amp;channelID, &quot;channelID&quot;, &quot;<strong>mychannel&quot;</strong>, &quot;The channel ID to deliver from.&quot;)</pre><p>The following parameters are self-explanatory.</p><p>The only thing that I would like to add here is that in most of the cases, we are going to have tls enabled, so if tls is enabled in our configuration we should have <em>tls</em> and <em>mTls</em> parameters set to true.</p><pre>flag.BoolVar(&amp;quiet, &quot;quiet&quot;, false, &quot;Only print the block number, will not attempt to print its block contents.&quot;)</pre><pre>flag.BoolVar(&amp;filtered, &quot;filtered&quot;, false, &quot;Whenever to read filtered events from the peer delivery service or get regular blocks.&quot;)</pre><pre>flag.BoolVar(&amp;tlsEnabled, &quot;tls&quot;, true, &quot;TLS enabled/disabled&quot;)</pre><pre>flag.BoolVar(&amp;mTlsEnabled, &quot;mTls&quot;, true, &quot;Mutual TLS enabled/disabled (whenever server side validates clients TLS certificate)&quot;)</pre><p>Here, we have some very important parameters:</p><ul><li><em>clientKey </em>which is <em>server.key</em> file</li><li><em>clientCert </em>which is <em>server.crt</em> file</li><li><em>rootCert</em> which is <em>ca.crt</em> or <em>ca.pem</em> file</li></ul><p>If you don’t want to look through your configuration, you can use <em>locate</em> command:</p><blockquote>$ locate server.key</blockquote><p>For BYFN, the paths are as follows:</p><pre>clientKey := &quot;~/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/<strong>peers</strong>/peer0.org1.example.com/tls/server.key&quot;</pre><pre>clientCert := &quot;~/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/<strong>peers</strong>/peer0.org1.example.com/tls/server.crt&quot;</pre><pre>rootCert := &quot;~/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/<strong>peers</strong>/peer0.org1.example.com/tls/ca.crt&quot;</pre><p>Here, you can choose between <em>OLDEST</em> and <em>NEWEST</em> blocks:</p><pre>flag.IntVar(&amp;seek, &quot;seek&quot;, OLDEST, &quot;Specify the range of requested blocks.&quot;+<br>&quot;Acceptable values:&quot;+<br>&quot;-2 (or -1) to start from oldest (or newest) and keep at it indefinitely.&quot;+<br>&quot;N &gt;= 0 to fetch block N only.&quot;)</pre><p>Next, go to <em>initMSP() </em>function.</p><p>There are three parameters you should pay attention to:</p><ul><li>msp configuration directory</li><li>mspID</li><li>mspType</li></ul><p><em>Hint!</em> You would find the following command useful:</p><pre>$ docker explore container_name</pre><p>The only parameter that can make you stop and think for a while is <em>mspType</em>.</p><p>If you do not have it written in your configuration, no need to worry; it means that the default parameter — <em>bccsp</em> — will be used.</p><pre>var mspMgrConfigDir = &quot;~/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/<strong>Admin</strong>@org1.example.com/msp&quot;</pre><pre>var mspID = &quot;Org1MSP&quot;</pre><pre>var mspType = &quot;bccsp&quot;</pre><p>Some information I want to share that also would probably satisfy your curiosity.</p><p>In HyperLedger Fabric, the following MSP types are possible:</p><ul><li>Idemix-based MSP</li><li>BCCSP-based (X509) MSP [default]</li></ul><p>The main difference between those two is the signature scheme.</p><p>You can read more about it in the official <a href="https://hyperledger-fabric.readthedocs.io/en/release-1.4/idemix.html">documentation</a>.</p><h3><strong>Step 3</strong></h3><p>If you are one of those lucky people who can run events client without conducting the following modifications — go for it! I had to spend some time trying to figure out the reasons of the constantly appearing error message when launching eventsclient.</p><p>What we need to do here is to modify <em>client.go</em> file, which is located in <em>comm</em> folder:</p><pre>$ cd $GOPATH/src/github.com/hyperledger/fabric/core/comm</pre><p>In <em>client.go</em> file, find function <em>NewConnection()</em> and comment the following line:</p><pre>conn, err := grpc.DialContext(ctx, address, dialOpts…)</pre><p>Instead of using the commented line, put the following code:</p><pre>certificate := &quot;~/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt&quot;</pre><pre>creds, errMsg := credentials.NewClientTLSFromFile(certificate, &quot;&quot;)</pre><pre>if errMsg != nil {<br>   return nil, fmt.Errorf(&quot;Failed to load tls certificate when   getting credentials : %s&quot;, errMsg)<br>}</pre><pre>conn, err := grpc.Dial(address, grpc.WithTransportCredentials(creds))</pre><p>Note that the path specified in the certificate variable is as same as the path that we have used for <em>clientCert</em> in <em>readCLInputs() </em>function.</p><h3><strong>Step 4</strong></h3><p>Next, we need to set <em>FABRIC_CFG_PATH</em> environment variable to point to the folder that contains the channel configuration file (<em>configtx.yaml</em>)</p><p>Remember that our <em>ROOT</em> variable stores the name of this file.</p><pre>$ export FABRIC_CFG_PATH=/~/fabric-samples/first-network</pre><h3><strong>Step 5</strong></h3><p>Now, we can finally launch our events client.</p><pre>$ go run eventsclient.go</pre><p>If everything is working well, you will see something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhPQoM4SJ5yDycmuQuVccQ.png" /></figure><p>Note that chaincode event payload (message) is actually encoded to base64 so don’t be surprised if you see something like this in the display</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9n07KT7Atl1XxaKuYWhSOg.png" /></figure><p>In this case, it will be the name of the chaincode that we have upgraded — <em>mycc</em>.</p><p>If you are curious you can decode the message and <a href="https://www.base64decode.org/">see it yourself</a>.</p><h3><strong>Bonus</strong></h3><p>What if you need to see the information on chaincode event only?</p><p>Here is a simple idea on how to do it for <em>filtered</em> events.</p><pre>flag.BoolVar(&amp;filtered, &quot;filtered&quot;, <strong>true</strong>, &quot;Whenever to read filtered events from the peer delivery service or get regular blocks.&quot;)</pre><p>There is one additional function we need to write:</p><pre>func FindEvent(s interface{}) (bool, string) {</pre><pre>value := fmt.Sprintf(&quot;%v&quot;, s)<br>if value != &quot;&quot; {<br>  return true, value<br>}</pre><pre>return false, &quot;&quot;<br>}</pre><p>Now jump to <em>readEventsStream() </em>function, find <em>*peer.DeliverResponse_FilteredBlock </em>and paste this <strong>additional code</strong>.</p><pre>case *peer.DeliverResponse_FilteredBlock:<br>if !quiet {<br>  logger.Info(&quot;Received filtered block: &quot;)<br>  err := protolator.DeepMarshalJSON(os.Stdout, t.FilteredBlock)<br> <br>  if err != nil {<br>    logger.Error(&quot;Error pretty printing filtered block: %s&quot;, err)<br>  }</pre><pre>  <strong>var txActions *peer.FilteredTransactionActions<br>  filteredTxs := t.FilteredBlock.FilteredTransactions<br>  <br>  for _, tx := range filteredTxs {<br>    txActions = tx.GetTransactionActions()<br>  }</strong></pre><pre><strong>  eventExists, eventInfo := FindEvent(txActions)<br>  if eventExists == true {<br>    logger.Info(&quot;Found chaincode event : &quot;, eventInfo)<br>  }</strong><br>}</pre><p>By doing so, you will get information on filtered blocks displayed along with the event information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3Myzm56_KxzkBTtsgYY4w.jpeg" /></figure><h3><strong>The errors you might encounter and how to fix it</strong></h3><blockquote>panic: fatal error when initializing configtx config : error when reading configtx config file: While parsing config: yaml: unknown anchor ‘OrdererDefaults’ referenced</blockquote><p>References ( ‘&amp;’) must be defined earlier in the document — before they are referenced ( ‘&lt;&lt;: *’).</p><p>Therefore, you need to check the location of your profiles section in the file. Make sure it is placed at the end of the file.</p><blockquote>[eventsclient] main -&gt; INFO 001 Error connecting: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = “transport: authentication handshake failed: x509: certificate is valid for <strong>peer0.org1.example.com, peer0</strong>, not localhost”</blockquote><p>Check server parameter in <em>readCLInputs()</em> function:</p><pre>flag.StringVar(&amp;serverAddr, &quot;server&quot;, &quot;<strong>peer0.org1.example.com:7051&quot;</strong>, &quot;The RPC server to connect to.&quot;)</pre><blockquote>Error connecting: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = “transport: Error while dialing dial tcp: lookup peer0.org1.example.com on 127.0.0.53:53: no such host”</blockquote><p>Error appears when you do not have entry for <em>peer0.org1.example.com </em>in <em>/etc/hosts</em>.</p><p>Use the following command to add it:</p><pre>$ sudo vi /<em>etc/</em>hosts</pre><p>127.0.0.53 peer0.org1.example.com</p><p>or</p><pre>$ echo &quot;127.0.0.53 peer0.org1.example.com&quot; | sudo tee -a /etc/hosts</pre><blockquote>[eventsclient] readEventsStream -&gt; INFO 001 Got status &amp;{NOT_FOUND}</blockquote><p>You have used the wrong <em>channelID</em> or did not specify it at all in <em>readCLInputs()</em> function.</p><pre>flag.StringVar(&amp;channelID, &quot;channelID&quot;, <strong>channelID</strong>, &quot;The channel ID to deliver from.&quot;)</pre><blockquote>[eventsclient] main -&gt; INFO 001 Error connecting: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = “transport: authentication handshake failed: x509: certificate signed by unknown authority</blockquote><blockquote>[eventsclient] main -&gt; INFO 001 Error creating grpc client: failed to load client certificate: tls: private key does not match public key</blockquote><p>The certificates that you have specified in your path are wrong.</p><p>“<em>unknown authority</em>” implies that ca certificate (<em>rootCert</em>) that you have provided is invalid.</p><p>So, check the path to your certificates and make sure that you have used the certificates provided for peer.</p><blockquote>panic: fatal error when initializing core config : Could not find config file. Please make sure that FABRIC_CFG_PATH or — configPath is set to a path which contains configtx.yaml</blockquote><p>You have to tell where to look for the <em>configtx.yaml</em> file. Make sure to set FABRIC_CFG_PATH environment variable. Take a look at Step 4.</p><blockquote>cannot find package “github.com/spf13/viper” in any of:</blockquote><blockquote>/opt/go/src/github.com/spf13/viper (from $GOROOT)</blockquote><blockquote>/opt/gopath/src/github.com/spf13/viper (from $GOPATH)</blockquote><p>Install necessary tools via <em>go get </em>command</p><pre>$ go get -u github.com/spf13/viper</pre><blockquote>readEventsStream -&gt; INFO 001 Error receiving: rpc error: code = Unavailable desc = transport is closing</blockquote><p>Perform the actions described in <em>Step 3</em> and modify <em>client.go</em> file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2484614a9e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>