@@ -69,10 +69,11 @@ automatically download, extract, and run when you execute the `docker-compose` c
69
69
## Commands
70
70
71
71
The channel commands are:
72
- * "create" - create and name a channel in the ` orderer ` and get back a genesis
72
+
73
+ * ` create ` - create and name a channel in the ` orderer ` and get back a genesis
73
74
block for the channel. The genesis block is named in accordance with the channel name.
74
- * " join" - use the genesis block from the ` create ` command to issue a join
75
- request to a Peer .
75
+ * ` join ` - use the genesis block from the ` create ` command to issue a join
76
+ request to a peer .
76
77
77
78
## Use Docker to spawn network entities & create/join a channel
78
79
@@ -84,7 +85,7 @@ Create network entities, create channel, join peers to channel:
84
85
``` bash
85
86
docker-compose -f docker-compose-gettingstarted.yml up -d
86
87
```
87
- Behind the scenes this started six containers (3 peers, a "solo" orderer, CLI and CA)
88
+ Behind the scenes this started six containers (3 peers, a "solo" orderer, cli and CA)
88
89
in detached mode. A script - ` channel_test.sh ` - embedded within the
89
90
` docker-compose-gettingstarted.yml ` issued the create channel and join channel
90
91
commands within the CLI container. In the end, you are left with a network and
@@ -95,18 +96,17 @@ View your containers:
95
96
# if you have no other containers running, you will see six
96
97
docker ps
97
98
```
98
-
99
99
Ensure the channel has been created and peers have successfully joined:
100
100
``` bash
101
- docker exec -it cli sh
101
+ docker exec -it cli bash
102
102
```
103
103
You should see the following in your terminal:
104
104
``` bash
105
105
/opt/gopath/src/github.com/hyperledger/fabric/peer #
106
106
```
107
107
To view results for channel creation/join:
108
108
``` bash
109
- cat results.txt
109
+ more results.txt
110
110
```
111
111
You're looking for:
112
112
``` bash
@@ -116,15 +116,20 @@ SUCCESSFUL JOIN CHANNEL on PEER1
116
116
SUCCESSFUL JOIN CHANNEL on PEER2
117
117
```
118
118
119
- To verify the genesis block for the channel was created you can issue:
119
+ To view genesis block:
120
+ ``` bash
121
+ more myc1.block
122
+ ```
123
+
124
+ Exit the cli container:
120
125
``` bash
121
- ls -ltr myc1.block
126
+ exit
122
127
```
123
128
124
129
## Curl the application source code and SDK modules
125
130
126
131
* Prior to issuing the command, make sure you are in the same working directory
127
- where you curled the network code.
132
+ where you curled the network code. AND make sure you have exited the cli container.
128
133
* Execute the following command:
129
134
``` bash
130
135
curl -OOOOOO https://raw.githubusercontent.com/hyperledger/fabric-sdk-node/master/examples/balance-transfer/{config.json,deploy.js,helper.js,invoke.js,query.js,package.json}
@@ -147,93 +152,147 @@ the provisioned Certificate Authority. Once the client is properly authenticate
147
152
the programs will demonstrate basic chaincode functionalities - deploy, invoke, and query. Make
148
153
sure you are in the working directory where you pulled the source code before proceeding.
149
154
155
+ Upon success of each node program, you will receive a "200" response in the terminal.
156
+
150
157
Register/enroll & deploy chaincode (Linux or OSX):
151
158
``` bash
159
+ # Deploy initializes key value pairs of "a","100" & "b","200".
152
160
GOPATH=$PWD node deploy.js
153
161
```
154
162
Register/enroll & deploy chaincode (Windows):
155
163
``` bash
164
+ # Deploy initializes key value pairs of "a","100" & "b","200".
156
165
SET GOPATH=%cd%
157
166
node deploy.js
158
167
```
159
- Issue an invoke. Move units from "a" to "b":
168
+ Issue an invoke. Move units 100 from "a" to "b":
160
169
``` bash
161
170
node invoke.js
162
171
```
163
- Query against key value "a ":
172
+ Query against key value "b ":
164
173
``` bash
174
+ # this should return a value of 300
165
175
node query.js
166
176
```
167
- You will receive a "200 response" in your terminal if each command is successful.
168
- Explore the various javascript programs to better understand the SDK and APIs.
177
+ Explore the various node.js programs, along with ` example_cc.go ` to better understand
178
+ the SDK and APIs.
169
179
170
- ## Manually create and join channel (optional)
180
+ ## Manually create and join peers to a new channel
181
+
182
+ Use the cli container to manually exercise the create channel and join channel APIs.
183
+
184
+ Channel - ` myc1 ` already exists, so let's create a new channel named ` myc2 ` .
171
185
172
- To manually exercise the create channel and join channel APIs through the CLI container, you will
173
- need to edit the Docker Compose file. Use an editor to open ` docker-compose-gettingstarted.yml ` and
174
- comment out the ` channel_test.sh ` command in your cli image. Simply place a ` # ` to the left
175
- of the command. For example:
176
- ``` bash
177
- cli:
178
- container_name: cli
179
- < CONTENT REMOVED FOR BREVITY>
180
- working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
181
- # command: sh -c './channel_test.sh; sleep 1000'
182
- # command: /bin/sh
183
- ```
184
186
Exec into the cli container:
185
187
``` bash
186
- docker exec -it cli sh
188
+ docker exec -it cli bash
187
189
```
188
190
If successful, you should see the following in your terminal:
189
191
``` bash
190
192
/opt/gopath/src/github.com/hyperledger/fabric/peer #
191
193
```
192
194
Send createChannel API to Ordering Service:
193
195
```
194
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer channel create -c myc1
196
+ CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer channel create -c myc2
195
197
```
196
- This will return a genesis block - ` myc1 .block` - that you can issue join commands with.
198
+ This will return a genesis block - ` myc2 .block` - that you can issue join commands with.
197
199
Next, send a joinChannel API to ` peer0 ` and pass in the genesis block as an argument.
198
200
The channel is defined within the genesis block:
199
201
```
200
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc1 .block
202
+ CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc2 .block
201
203
```
202
204
To join the other peers to the channel, simply reissue the above command with ` peer1 `
203
205
or ` peer2 ` specified. For example:
204
206
```
205
- CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc1 .block
207
+ CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer1:7051 peer channel join -b myc2 .block
206
208
```
207
209
Once the peers have all joined the channel, you are able to issues queries against
208
210
any peer without having to deploy chaincode to each of them.
209
211
210
- ## Use cli to deploy, invoke and query (optional)
212
+ ## Use cli to deploy, invoke and query
211
213
212
214
Run the deploy command. This command is deploying a chaincode named ` mycc ` to
213
- ` peer0 ` on the Channel ID ` myc1 ` . The constructor message is initializing ` a ` and
215
+ ` peer0 ` on the Channel ID ` myc2 ` . The constructor message is initializing ` a ` and
214
216
` b ` with values of 100 and 200 respectively.
215
217
```
216
- CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode deploy -C myc1 -n mycc -p github.com/hyperledger/fabric/examples -c '{"Args":["init","a","100","b","200"]}'
218
+ CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode deploy -C myc2 -n mycc -p github.com/hyperledger/fabric/examples -c '{"Args":["init","a","100","b","200"]}'
217
219
```
218
220
Run the invoke command. This invocation is moving 10 units from ` a ` to ` b ` .
219
221
```
220
- CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode invoke -C myc1 -n mycc -c '{"function":"invoke","Args":["move","a","b","10"]}'
222
+ CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode invoke -C myc2 -n mycc -c '{"function":"invoke","Args":["move","a","b","10"]}'
221
223
```
222
224
Run the query command. The invocation transferred 10 units from ` a ` to ` b ` , therefore
223
225
a query against ` a ` should return the value 90.
224
226
```
225
- CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode query -C myc1 -n mycc -c '{"function":"invoke","Args":["query","a"]}'
227
+ CORE_PEER_ADDRESS=peer0:7051 CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 peer chaincode query -C myc2 -n mycc -c '{"function":"invoke","Args":["query","a"]}'
226
228
```
227
229
You can issue an ` exit ` command at any time to exit the cli container.
228
230
231
+ ## Creating your initial channel through the cli
232
+
233
+ If you want to manually create the initial channel through the cli container, you will
234
+ need to edit the Docker Compose file. Use an editor to open ` docker-compose-gettingstarted.yml ` and
235
+ comment out the ` channel_test.sh ` command in your cli image. Simply place a ` # ` to the left
236
+ of the command. (Recall that this script is executing the create and join channel
237
+ APIs when you run ` docker-compose up ` ) For example:
238
+ ``` bash
239
+ cli:
240
+ container_name: cli
241
+ < CONTENT REMOVED FOR BREVITY>
242
+ working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
243
+ # command: sh -c './channel_test.sh; sleep 1000'
244
+ # command: /bin/sh
245
+ ```
246
+
247
+ Then use the cli commands from the prior two sections.
248
+
229
249
## Troubleshooting (optional)
230
250
231
- If you have existing containers running you may receive an error indicating that a port is
251
+ If you have existing containers running, you may receive an error indicating that a port is
232
252
already occupied. If this occurs, you will need to kill the container that is using said port.
233
253
234
254
If a file cannot be located, make sure your curl commands executed successfully and make
235
255
sure you are in the directory where you pulled the source code.
236
256
257
+ If you are receiving timeout or GRPC communication errors, try restarting your
258
+ failing docker process. For example:
259
+ ``` bash
260
+ docker stop peer0
261
+ ```
262
+ Then:
263
+ ``` bash
264
+ docker start peer0
265
+ ```
266
+
267
+ Another approach to GRPC and DNS errors (peer failing to resolve with orderer and vice
268
+ versa) is to hardcode the IP addresses for each. You will know if there is a DNS
269
+ issue, because a ` more results.txt ` command within the cli container will display
270
+ something similar to:
271
+ ``` bash
272
+ ERROR CREATING CHANNEL
273
+ PEER0 ERROR JOINING CHANNEL
274
+ ```
275
+
276
+ Issue a ` docker inspect <container_name> ` to ascertain the IP address. For example:
277
+ ``` bash
278
+ docker inspect peer0 | grep IPAddress
279
+ ```
280
+ AND
281
+ ``` bash
282
+ docker inspect orderer | grep IPAddress
283
+ ```
284
+ Take these values and hard code them into your cli commands. For example:
285
+ ``` bash
286
+ CORE_PEER_COMMITTER_LEDGER_ORDERER=172.21.0.2:7050 peer channel create -c myc1
287
+ ```
288
+ AND THEN
289
+ ``` bash
290
+ CORE_PEER_COMMITTER_LEDGER_ORDERER=< IP_ADDRESS> CORE_PEER_ADDRESS=< IP_ADDRESS> peer channel join -b myc1.block
291
+ ```
292
+
293
+ If you are seeing errors while using the node SDK, make sure you have a current version
294
+ of node.js and npm installed on your machine.
295
+
237
296
If you ran through the automated channel create/join process (i.e. did not comment out
238
297
` channel_test.sh ` in the ` docker-compose-gettingstarted.yml ` ), then channel - ` myc1 ` - and
239
298
genesis block - ` myc1.block ` - have already been created and exist on your machine.
@@ -259,8 +318,9 @@ Then join:
259
318
CORE_PEER_COMMITTER_LEDGER_ORDERER=orderer:7050 CORE_PEER_ADDRESS=peer0:7051 peer channel join -b myc2.block
260
319
```
261
320
262
- If you do choose to create a new channel, you will also need to edit the "channelID" parameter
263
- in the ` config.json ` file to match the new channel's name. For example:
321
+ If you do choose to create a new channel, and want to run deploy/invoke/query with
322
+ the node.js programs, you also need to edit the "channelID" parameter in the
323
+ ` config.json ` file to match the new channel's name. For example:
264
324
```
265
325
{
266
326
"chainName":"fabric-client1",
@@ -271,7 +331,17 @@ in the `config.json` file to match the new channel's name. For example:
271
331
```
272
332
273
333
OR, if you want your channel called - ` myc1 ` -, remove your docker containers and
274
- then follow the same commands in the __ Manually create and join channel__ section.
334
+ then follow the same commands in the __ Manually create and join peers to a new channel__
335
+ section.
336
+
337
+ ## Clean up
338
+
339
+ Shut down your containers:
340
+ ``` bash
341
+ docker-compose -f docker-compose-gettingstarted.yml down
342
+ ```
343
+
344
+ ## Helpful Docker tips
275
345
276
346
Remove a specific docker container:
277
347
``` bash
0 commit comments