DevNet Sandbox: BlockChain Sandbox
DevNet Sandbox: BlockChain Sandbox
Hello World Example - Instructions
Quick Start:
In this quick start, we’re going to perform a very simple transaction, involving simulating sending some cryptocurrency from one peer organisation, to another (Org1 to Org2).
So, we've taken example code from the HyperLedger git repo – ‘chaincode_example02’ available here - and instantiated it on two of the sandbox blockchain peer nodes as ‘mycc’:
We have already run "instantiated" scripts below to create user1/user2 and assign token ‘values’ to them (Note: The steps below is no need to run mannauly since they are executed in our lab setup)
- create channel
peer channel create -c businesschannel --tls true -f ./channel-artifacts/channel.tx
- All 4 Peers join channel peer channel join -b businesschannel.block
- Set the anchor peers for each org peer channel update -c businesschannel
- Install chaincode peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02
- Instantiate chaincode peer chaincode instantiate -C businesschannel n mycc -v 1.0 -c '{"Args":["init","user1","100","user2","200"]}
And here is commands to run the "Hello world" example:
- SSH into Fabric-CLI using 10.10.20.38 and credentials [cli/cisco123]
- input the query statement:
- peer chaincode query -C businesschannel -n mycc -c '{"Args":["query","user1"]}'
- This will return some verbose output, but also the line ‘query result: 100’, which is what we’re looking for. This proves out that user1 from the query line, equals 100.
- input the query statement:
- peer chaincode query -C businesschannel -n mycc -c '{"Args":["query","user2"]}'
- This will return some verbose output, but also the line ‘query result: 200’, which is what we’re looking for. This proves out that user2 from the query line, equals 200.
- Now, to transfer 10 of user1 to user2 input this action statement:
- ORDERER_CA="/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem" && peer chaincode invoke --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C businesschannel -n mycc -c '{"Args":["invoke","user1","user2","10"]}'
- There’s a lot of verbose out here, too…but check out the ‘Chain invoke successful’
The state change PROPOSE message will be sent to all ledgers i.e. endorsing peers. The peers simulate a transaction and produce an endorsement signature back to the Fabric-CLI client.
The CLI client collects an endorsement for a transaction and broadcasts it through the orderer node if the proposal endorsed by enough peers. The Orderer node then delivers the transactions to all peers.
- We can now check key value user1 again to make sure it is 90, using the query from step 2
- We can also check key value user2 is equal to 210, using the query in step 3
- We can also check the ‘state’ DB from any peer that participated in the transaction validation.
- SSH into Peer1 (Peer 1 Org1) using 10.10.20.38 and credentials [peer1/cisco123]
- Check the modification time of the state DB file by Inputting the following command and checking the timestamp: ls --full-time /var/hyperledger/production/ledgersData/chains/chains/businesschannel/blockfile_000000
And that’s it! You’ve successfully transferred some value from one peer account to another on the HyperLedger Blockchain. Now dive into the HyperLedger Blockchain Documentation to learn much more!
Some more information about our HyperLedger Deployment in this Sandbox:
- We are using LevelDB to store State database, please visit http://hyperledger-fabric.readthedocs.io/en/latest/ledger.html for those data storage details
- You can also install your own chaincode like this:
- peer chaincode install -v 2.0 -n helloworld -p github.com/hyperledger/fabric/examples/chaincode/go/helloworld
- And then instantiate it:
- peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n helloworld -v 2.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
-
The detailed chaincode cmdlets could be found at http://hyperledger-fabric.readthedocs.io/en/latest/chaincode4noah.html