Hyperledger Fabric - balance transfer (1) Startup example

Blacne transfer is an example application of the Hyperledger fabric Node SDK. It mainly uses the APIs in the fabric-client and fabric-ca-client modules in the SDK to implement various operations that interact with the Fabric network.

prerequisites

  • Docker - v1.12 or higher
  • Docker Compose - v1.8 or higher
  • Git - needed for clone commands
  • Node.js - v8.4.0 or higher
  • Docker images
  • jq - needed for execute the test script

Download example

It should be noted that the balance transfer example varies greatly between different versions, and there are major changes from v1.0.6 to v1.1.0. The latest version release-1.1 is used here.

git clone https://github.com/hyperledger/fabric-samples.git
cd fabric-samples/balance-transfer

Run the example

Compared with the samples in the previous running Fabric project, the two examples e2e and first-network use a cli container to simulate the client interacting with the network. The balance-transfer will listen on a port, and users can perform corresponding operations according to the URL through tools such as curl commands and browsers.
The example can be run from a script to build a local Fabric network with all nodes including:

  • 2 cases
  • 1 SOLO orderer
  • 4 peers (2 peers per Org)
method one

Execute the script in terminal 1:

./runApp.sh
  • Start the local fabric network
  • Download the fabric-client and fabric-ca-client modules
  • listen on port 4000

To test the network on Terminal 2, download the test script before executing jq:

sudo apt-get install jq
./testAPIs.sh
  • Create channel and join node
  • Install and instantiate chaincode
  • Execute (invoke) chaincode
  • make various queries
Method Two

Execute in terminal 1:

docker-compose -f artifacts/docker-compose.yaml up

Execute the command in Terminal 2 to download the fabric-client and fabric-ca-client modules:

npm install

Run the node app and listen on port 4000:

PORT=4000 node app

Test with curl command in terminal 3.

Error solution

Note: balance transferThe version should match the version of the image file, otherwise an error will occur.
For example, my image file download is v1.0.0, and the fabric-samples project does not have this version (use git tagview), then an error occurs in the first step of registering a user No identity type provided:

No identity type provided. Please provide identity type

Then you need to re-download the corresponding version of the mirror, and switch the project version to keep the two consistent.

turn off the network

# 清除所有容器
docker rm -f $(docker ps -aq)
# 删除chaincode镜像
docker rmi -f $(docker images | grep dev | awk '{print $3}')
# 删除用户注册和登录的数据,如私钥和证书
rm -rf fabric-client-kv-org[1-2]

Reference: http://www.cnblogs.com/studyzy/p/7437157.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325937304&siteId=291194637