A recent project required the concept of a super ledger and then looked up the information online. Finally, Fabric was chosen as the target of experimental play. The v0.6 version was abandoned, but as of this post, V1.0 is still in alpha. The following environment setup steps are largely derived from hyperledger-fabric.readthedocs. IO. You can also readthe tutorial there if you are good at English. (I need to make fun of the hashtag of the article, because MY reputation is not enough to edit and create Hyperledger hashtag)

The launching

You have to prepare

  • GO the latest version of GO

  • Docker version 1.13 or later

  • Docker Compose version 1.8 or above

  • Node.js & NPM is always the latest, but be aware of the correspondence between the two versions

  • Xcode users with Big Apple will need to install it

  • Git Latest Version

  • Hyperledger Fabric concept understanding

  • Mac or Linux operating environment

You’d better

  1. Understand the basic concepts of superledgers (Introductory video on YouTube)

  2. Know the basic directory structure of GO, and the setting of environment variables

  3. Learn about Docker and Docker-compose, and some basic operations

  4. There are wall climbing conditions

Set up

Access to the mirror

$mkdir -p

/hackfest CD

/hackfest create a directory where you need to place the source code

Download the necessary scripts including Docker compose script, channel script, crypto material for identity attestation, etc… $ curl -L https://raw.githubusercontent.com/hyperledger/fabric/master/examples/sfhackfest/sfhackfest.tar.gz -o sfhackfest.tar.gz 2> /dev/null; Tar – XVF sfhackfest. Tar. Gz after decompression may quote a tar little mistakes, no relationship

Check your directory structure. Normal should look like this:

Use the docker – compose, Pull the fabric – peer, fabric – orderer, The fabric-ca and CLI docker-compose definition file is docker-compose- gettingStarted. Yml $docker-compose- f docker-compose-gettingstarted.yml build

$docker-compose -f docker-compose- gettingStarted. Yml up -d

The channel_test.sh script is used to create and add channels. Click here to see what channel_test.sh does.

Verify the environment

Use $docker ps to check if the container has been successfully started. Normally there should be 6 containers running, including 3 peer nodes, an Orderer, a CA and a CLI

We enter cli containers take a look at each node to join channel situation $docker exec – it cli bash command line into $/ opt/gopath/src/github.com/hyperledger/fabric/peer # Enter the query command $more result. TXT to get the result



SUCCESSFUL CHANNEL CREATION
SUCCESSFUL JOIN CHANNEL on PEER0
SUCCESSFUL JOIN CHANNEL on PEER1
SUCCESSFUL JOIN CHANNEL on PEER2
Copy the code

Look at thechannel_test.shThe creation block created by the script

$ more myc1.block

It would be nice to see a long list of genesis blocks below

Access to the SDK

In Fabric V1.0, there are two methods to invoke the interface: CLI and SDK. Since Fabric uses all GRPC communication methods, using SDK makes it easier to forge our own client and communicate with the back-end blockchain network. To cUrl the examples in the Fabric-SDK-node project, run NPM install. $ curl -OOOOOO https://raw.githubusercontent.com/hyperledger/fabric-sdk-node/v1.0-alpha/examples/balance-transfer/ {config. Json, deploy. J s,helper.js,invoke.js,query.js,package.json}

$NPM install: $NPM install: $NPM install: $NPM install

$GOPATH=$PWD or $GOPATH=’ /

/

/< Hackfest >’ to check if GOPATH is set correctly with $go env

At this point, the environment and code we need are set up.

Play with the SDK

Register and deploy

NPM install failed when extension_binary/grpc_node.node is not installed. Repeat the previous NPM install

After successful execution, the following trop is returned



Chaincode deployed successfully, and we initialized a simulation:

aHave 100 RMB

bHave 200 RMB

Test chaincode

$node invoke.js transfers RMB 100 from A to B

The query results

$node query $node query $node query



[2017-03-18 15:47:06.676] [INFO] QUERY - # # # # # ## # # # # #### Query results after the move on PEER0, User "b" now has "300"Copy the code

Now B has 300 RMB! Which means our transfer was successful

Here we have completed a super ledger simulation environment, and test success. To be continued, next version: + Write your own Chaincode

[I am steak, reproduced please indicate the source segmentfault.com/a/11…