hyperledger / fabric-sdk-go

https://wiki.hyperledger.org/display/fabric
Apache License 2.0
911 stars 511 forks source link

Add examples on how we can create the fabric-sdk-go config.yaml file, in order to be able to instantiate an sdk instance. #209

Open GeoMisiak opened 2 years ago

GeoMisiak commented 2 years ago

According to the fabric-samples, within the first-network and test-network there are two templates, one json file and one yaml file that are being created when network started. Using the ccp-generate.sh we can fill with these templates with the latest pem files. These files will be used later from the API in order to be able to execute SubmitTransaction and EvaluateTransaction and interact with the smart contract.

What I am trying to achieve? I am trying to fetch the latest block for from the channel , using qscc chaincode queries against peers. When I am trying to load the aforementioned json file in order to be able to create a channel context using the following command: sdk, err := fabsdk.New(config.FromFile("<path to connection-org1.json file>"))

I am getting the following error: Failed to create fabric sdk: failed to create identity manager provider: failed to initialize identity manager for organization: org1: Either a cryptopath or an embedded list of users is required.

What is the correct format of the config file that we need to create in order to be able to create the sdk instance correctly?

afrancoc2000 commented 2 years ago

Hi @GeoMisiak here is the template for the config.yaml https://github.com/hyperledger/fabric-sdk-go/blob/main/pkg/core/config/testdata/template/config.yaml and in this folder you can find some examples: https://github.com/hyperledger/fabric-sdk-go/tree/main/test/fixtures/config What the error is telling you is that you need a crypto path or a list of users under organization something like this:

With cryptoPath:

organizations:
  Org1:
    mspid: Org1MSP
    cryptoPath: /go/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp

With users:

organizations:
  Org1:
    mspid: Org1MSP
    users:
      Admin:
        cert:
          path: /go/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/cert.pem
        key:
          path: /go/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/key.pem

Hope it helps