- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 307字
- 2021-06-24 14:59:35
How to do it...
To use CouchDB, follow these steps:
- Make sure network is not up. If it is up, shut down the network, as shown here:
$ cd fabric-samples/first-network
$ sudo ./byfn.sh down
- Start up the BYFN network using CouchDB:
Here we will start up the network by using the CouchDB database.
$ cd fabric-samples/first-network
$ sudo ./byfn.sh up -c mychannel -s couchdb
Following screenshot shows our network starting up:

- Install chaincode by navigating into the CLI container using the command-line interface:
$ sudo docker exec -it cli bash
$ peer chaincode install -n marbles -v 1.0
-p github.com/chaincode/marbles02/go
- Instantiate the chaincode:
$ export CHANNEL_NAME=mychannel
$ peer chaincode instantiate -o orderer.example.com:7050
--tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
-C $CHANNEL_NAME -n marbles -v 1.0 -c '{"Args":["init"]}' -P "OR
('Org0MSP.peer','Org1MSP.peer')"
- Invoke the chaincode. The following commands invoke chaincode to create marble.
$ peer chaincode invoke -o orderer.example.com:7050 --tls
--cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
-C $CHANNEL_NAME -n marbles -c
'{"Args":["initMarble","marble5","blue","35","tom"]}'
Following screenshot shows successful creation of chanincode:

- Open the CouchDB UI by navigating to http://host-ip:5984/_utils/#/_all_dbs (in my case, my AWS public IP address is 3.91.245.92, so the URL is http://3.91.245.92:5984/_utils/#/_all_dbs):
In order to allow public access to CouchDB, we need open port 5984. Navigate to the AWS security group under the instance, launch the wizard, and choose Action | Edit Inbound Rules | Add Inbound Rule. This is shown as follows. After this, click Save. You can follow the below example to allow all IP address to access CouchDB:

- From mychannel_marbles, we can query and see the transaction ID with marble5:

- Click marble5, and you will see the default marble5 files:

Here, we saw how to use CouchDB to view how transactions get created, and updated them on the Fabric network. We will write a smart contract and deploy it as an application in the next recipe.
推薦閱讀
- 感官的盛宴:數(shù)學(xué)之眼看藝術(shù)(萬物皆數(shù)學(xué))
- 概率論與數(shù)理統(tǒng)計(jì)
- Data Visualization:a successful design process
- 數(shù)學(xué)建模與數(shù)學(xué)規(guī)劃:方法、案例及編程實(shí)戰(zhàn)(Python+COPT/Gurobi實(shí)現(xiàn))
- 數(shù)學(xué)也可以這樣學(xué):自然、空間和時(shí)間里的數(shù)學(xué)
- 你學(xué)的數(shù)學(xué)可能是假的
- 走近費(fèi)曼叢書:費(fèi)曼講物理:相對(duì)論
- 別說你不懂?dāng)?shù)學(xué)
- 現(xiàn)代數(shù)值計(jì)算(第2版)
- 硅谷工程師爸爸的超強(qiáng)數(shù)學(xué)思維課:激發(fā)孩子的數(shù)感天賦
- 怎樣解題:數(shù)學(xué)競(jìng)賽攻關(guān)寶典(第3版)
- Security with Go
- 高等數(shù)學(xué)習(xí)題全解與學(xué)習(xí)指導(dǎo)(下冊(cè))
- 這才是好讀的數(shù)學(xué)史
- 高等數(shù)學(xué)(上冊(cè))