Version: v1.1.0-preview Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2017 License: Apache-2.0 Imports: 13 Imported by: 0


What is block-listener

block-listener.go connects to a peer in order to receive block and chaincode events (if there are chaincode events being sent).

To Run

1. go build

2. ./block-listener -events-address=<peer-address> -events-from-chaincode=<chaincode-id> -events-mspdir=<msp-directory> -events-mspid=<msp-id>

Please note that the default MSP under fabric/sampleconfig will be used if no MSP parameters are provided.

Example with the e2e_cli example

The block listener can be used with TLS enabled or disabled. By default, the e2e_cli example will have TLS enabled. In order to allow the block-listener sample to connect to peers on e2e_cli example with a TLS enabled, the easiest way would be to map to the hostname of peer that you are connecting to, such as For example on *nix based systems this would be an entry in /etc/hosts file.

If you would prefer to disable TLS, you may do so by setting CORE_PEER_TLS_ENABLED=false in docker-compose-cli.yaml and base/peer-base.yaml as well as ORDERER_GENERAL_TLS_ENABLED=false inbase/docker-compose-base.yaml.

Next, run the e2e_cli example.

Once the "All in one" command:

./ up

has completed, attach the event client to peer by doing the following (assuming you are running block-listener in the host environment) if TLS is enabled:

CORE_PEER_TLS_ENABLED=true CORE_PEER_TLS_ROOTCERT_FILE=$GOPATH/src/ ./block-listener -events-mspdir=$GOPATH/src/ -events-mspid=Org1MSP

If TLS is disabled, you can simply run:

./block-listener -events-mspdir=$GOPATH/src/ -events-mspid=Org1MSP

The event client should output "Event Address:" and wait for events.

Exec into the cli container:

docker exec -it cli bash

Next, setup the environment variables for If TLS is enabled:


If TLS is disabled:


Create an invoke transaction. If TLS is enabled:

peer chaincode invoke -o --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'

If TLS is disabled:

peer chaincode invoke -o -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'

Now you should see the block content displayed in the terminal running the block listener.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.


The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL