Skip to content

Commit ed82446

Browse files
committed
1 parent 3eb8231 commit ed82446

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

Contents/blockchain/Hyperledger/Getting Start.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Dependencies
44

55
```bash
6-
sudo pacman -S git curl docker docker-compose go jq -y
6+
sudo pacman -S git curl docker docker-compose go jq tree -y
77
sudo systemctl enable docker.service
88
sudo systemctl enable docker.socket
99
sudo systemctl restart docker.service
@@ -25,7 +25,18 @@ curl -sSLO https://raw.githubusercontent.com/hyperledger/fabric/main/scripts/ins
2525
./install-fabric.sh
2626
```
2727

28-
## Run the test network
28+
## What’s happening behind the scenes?
29+
30+
If you are interested in learning more about the sample network, you can investigate the files and scripts in the test-network directory. The steps below provide a guided tour of what happens when you issue the command of ./network.sh up.
31+
32+
* `./network.sh` creates the certificates and keys for two peer organizations and the orderer organization. By default, the script uses the cryptogen tool using the configuration files located in the `organizations/cryptogen` folder. If you use the `-ca` flag to create Certificate Authorities, the script uses Fabric CA server configuration files and registerEnroll.sh script located in the `organizations/fabric-ca` folder. Both cryptogen and the Fabric CAs create the crypto material and MSP folders for all three organizations in the organizations folder.
33+
* Once the organization crypto material has been generated, the `network.sh` can bring up the nodes of the network. The script uses the `docker-compose-test-net.yaml` file in the docker folder to create the peer and orderer nodes. The docker folder also contains the `docker-compose-e2e.yaml` file that brings up the nodes of the network alongside three Fabric CAs.
34+
* If you use the createChannel subcommand, `./network.sh` runs the createChannel.sh script in the scripts folder to create a channel using the supplied channel name. The script uses the configtxgen tool to create the channel genesis block based on the TwoOrgsApplicationGenesis channel profile in the `configtx/configtx.yaml` file. After creating the channel, the script uses the peer cli to join `peer0.org1.example.com` and `peer0.org2.example.com` to the channel, and make both of the peers anchor peers.
35+
* If you issue the `deployCC` command, `./network.sh` runs the `deployCC.sh` script to install the asset-transfer (basic) chaincode on both peers and then define then chaincode on the channel. Once the chaincode definition is committed to the channel, the peer cli initializes the chaincode using the Init and invokes the chaincode to put initial data on the ledger.
36+
37+
## Running the test network with cryptogen tool
38+
39+
### Run the test network
2940

3041
```bash
3142
cd fabric-samples/test-network
@@ -34,6 +45,68 @@ cd fabric-samples/test-network
3445
docker ps -a
3546
```
3647

48+
### Create a channel
49+
50+
```bash
51+
./network.sh createChannel
52+
```
53+
54+
### Deploy the chaincode
55+
56+
The `deployCC` subcommand will install the `asset-transfer (basic)` chaincode on `peer0.org1.example.com` and `peer0.org2.example.com` and then deploy the chaincode on the channel specified using the channel flag (or mychannel if no channel is specified)
57+
58+
```bash
59+
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-go -ccl go
60+
```
61+
62+
### Interact with the chaincode
63+
64+
Because the endorsement policy for the asset-transfer (basic) chaincode requires the transaction to be `signed by Org1 and Org2`, the chaincode invoke command needs to target both `peer0.org1.example.com` and `peer0.org2.example.com` using the --peerAddresses flag
65+
66+
```bash
67+
export PATH=${PWD}/../bin:$PATH
68+
export FABRIC_CFG_PATH=$PWD/../config/
69+
70+
export CORE_PEER_TLS_ENABLED=true
71+
export CORE_PEER_LOCALMSPID="Org1MSP"
72+
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
73+
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
74+
export CORE_PEER_ADDRESS=localhost:7051
75+
76+
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"InitLedger","Args":[]}'
77+
78+
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}' | jq
79+
80+
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" --peerAddresses localhost:9051 --tlsRootCertFiles "${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
81+
82+
export CORE_PEER_TLS_ENABLED=true
83+
export CORE_PEER_LOCALMSPID="Org2MSP"
84+
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
85+
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
86+
export CORE_PEER_ADDRESS=localhost:9051
87+
88+
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}' | jq
89+
90+
./network.sh down
91+
```
92+
93+
## Running the test network with Certificate Authorities (CAs)
94+
95+
```bash
96+
./network.sh down
97+
./network.sh up -ca
98+
docker ps -a
99+
```
100+
101+
## Bring up the test network using BFT ordering service
102+
103+
```bash
104+
./network.sh down
105+
./network.sh up -bft
106+
./network.sh createChannel -bft
107+
docker ps -a
108+
```
109+
37110
## Reference
38111

39112
* <https://github.com/hyperledger/fabric-samples>

Contents/blockchain/Hyperledger/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,4 @@ Start with the [Getting Start](./Getting%20Start.md)
108108
* <https://www.youtube.com/@Hyperledger>
109109
* <https://hyperledger-fabric.readthedocs.io/en/latest/index.html>
110110
* <https://www.hyperledger.org/learn/training>
111+
* <https://training.linuxfoundation.org/training/hyperledger-fabric-for-developers-lfd272/>

0 commit comments

Comments
 (0)