It's a sample project for how to use fabric-sdk-go to use chaincode.
Directorys:
- config: config files of fabric network
- cli: codes to use chaincode
- write sdk config.yaml for byfn
- chaincode source code
- struct used for sdk operations
- get fabsdk
- install chaincode to a target peer
- instantiate chaincode
- invoke chaincode
- query chaincode
- upgrade chaincode's policy
- invoke chaincode with new policy
- query chaincode agian
- fetch chaincode information, policy included
-
Clone fabric-samples into your $GOPATH, and fabric-sdk-go-sample into a workspace not in you $GOPATH.
cd $GOPATH/src/github.com/hyperledger git clone [email protected]:hyperledger/fabric-samples.git cd ~ git clone [email protected]:Shitaibin/fabric-sdk-go-sample.git
-
Start byfn
cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network ./byfn.sh up
-
Modify config.yaml files. All config files in config directory, replace
/Users/shitaibin/go/src/github.com/hyperledger/fabric-samples/first-network/crypto-config
to${GOPATH}/src/github.com/hyperledger/fabric-samples/first-network/crypto-config
,${GOPAHT}
is your real GOPATH. -
Run chaincode sample by
go run main.go
,to instantiate a new chaincode and upgrade it.➜ cd fabric-sdk-go-sample/samples/chaincode ➜ chaincode git:(twoorg) ✗ go run main.go 2019/09/02 18:45:40 Initialized fabric sdk 2019/09/02 18:45:40 Initialized resource client 2019/09/02 18:45:40 Initialized channel client 2019/09/02 18:45:40 Initialized fabric sdk 2019/09/02 18:45:40 Initialized resource client 2019/09/02 18:45:40 Initialized channel client 2019/09/02 18:45:40 =================== Phase 1 begin =================== 2019/09/02 18:45:40 Chaincode has been installed on org1's peer 2019/09/02 18:45:40 Chaincode has been installed on org2's peer 2019/09/02 18:45:43 Instantitate chaincode tx: 87b91edc86725c427eafecf0edd5d88d35fec39bd808dea92700b594ce3c6702 2019/09/02 18:45:43 Chaincode has been instantiated 2019/09/02 18:45:45 invoke chaincode tx: 9f26cf9cf8afa93c6d4ae333d26766725b8246168f36a4c806b6c2f6b24a3274 2019/09/02 18:45:45 Invoke chaincode success 2019/09/02 18:45:45 query chaincode tx: c314524b9dd731dac399f44823fa6dee68d4a05f29deb26af83aee5d64e08fd3 2019/09/02 18:45:45 result: 90 2019/09/02 18:45:45 Query chaincode success on peer0.org1 2019/09/02 18:45:45 =================== Phase 1 end =================== 2019/09/02 18:45:45 =================== Phase 2 begin =================== 2019/09/02 18:45:45 Chaincode has been installed on org1's peer 2019/09/02 18:45:45 Chaincode has been installed on org2's peer 2019/09/02 18:46:14 Instantitate chaincode tx: a40b37781ebf5e42dc209a036c6dd1ae0562018915251d7bd66775dfa7552969 2019/09/02 18:46:14 Upgrade chaincode success for channel 2019/09/02 18:46:45 invoke chaincode tx: e01ed860b0a6c38911ff1215d1594496841148aec023545b890c9b28d1ba3b43 2019/09/02 18:46:45 Invoke chaincode success 2019/09/02 18:46:45 query chaincode tx: b329e4443cc78f183d19084f3dcac6267c44eacf905c3a2b728517ded211f5c2 2019/09/02 18:46:45 result: 1000 2019/09/02 18:46:45 Query chaincode success on peer0.org2 2019/09/02 18:46:45 =================== Phase 2 end ===================
-
Run event sample:
$ cd fabric-sdk-go-sample/samples/event $ go run main.go