How to Do Test Network and Deploy Chaincode

The test network is provided for learning about Fabric by running nodes on your local machine. Chaincode is a piece of code that is written in one of the supported languages such as Go or Java.

$cd fabric-samples/test-network

$./network.sh down    //Turn off historical network

$./network.sh up      //Start a new network

After the start up, next step is to view the docker content to check if the containers are running.

$docker ps -a     //View docker content

Next step is creating a channel.

./network.sh createChannel -c channelname    //Create channel with custom name
./network.sh  createChannel  //Default channel "mychannel"

If successful, the following interface will be displayed:

After successfully creating a channel, next step is deploy the chaincode.

./network.sh deployCC    //Deploy chaincode

If successful, the following interface will be displayed:

Using peer client to interact with chain code.

// Add environment variable

$export PATH=${PWD}/../bin:$PATH
$export FABRIC_CFG_PATH=$PWD/../config/
//Set interaction from Org1, modify as needed

$export CORE_PEER_TLS_ENABLED=true
$export CORE_PEER_LOCALMSPID="Org1MSP"
$export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
$export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
$export CORE_PEER_ADDRESS=localhost:7051

Query chain code.

$peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryCar","CAR9"]}'

$peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'

If successful, the following interface will be displayed:

After the test, shut down the network . The history of the chain will be cleared.

./network.sh down    //Turn off historical network

Leave a Comment

Your email address will not be published. Required fields are marked *