Giter Club home page Giter Club logo

fabric-sdk-go-sample's Introduction

Fabric sdk go sample

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

TODOs

  • 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

Quick start

  1. 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
    
  2. Start byfn

    cd $GOPATH/src/github.com/hyperledger/fabric-samples/first-network
    ./byfn.sh up
    

    byfn

  3. 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.

  4. 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 ===================
    

    byfn-sdk

  5. Run event sample:

    $ cd fabric-sdk-go-sample/samples/event
    $ go run main.go
    

fabric-sdk-go-sample's People

Contributors

shitaibin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.