hyperledger / fabric-samples

Samples for Hyperledger Fabric
https://wiki.hyperledger.org/display/fabric
Apache License 2.0
2.78k stars 3.37k forks source link

Chaincode only accepts the first contract in the export array - Typescript #1229

Closed ajiths10 closed 3 months ago

ajiths10 commented 3 months ago

Chaincode only accept the first contract in the export array.

image

image



 ### The first contract (AssetTransferContract) is accessible on both channels, but the other ones are not.

### Please advice me.

_Version - Latest_
bestbeforetoday commented 3 months ago

The problem might be the way your client application is invoking the smart contract. You need to explicitly request the correct contract within the chaincode package, for example:

const assetTransfer = network.getContract("basic", "AssetTransferContract");
const carGarage = network.getContract("basic", "CarGarageContract");

It seems that one of the contracts — for me, the first in the list — is selected as the default contract. The default contract is the one that will be called if you do not explicitly provide the contract name, for example:

const defaultContract = network.getContract("basic");

Note that the two contracts share the containing chaincode's namespace within the ledger so will have visibility of each other's ledger entries. If you want the ledger state of the two smart contracts to be separate, you should deploy them in separate chaincode packages.

ajiths10 commented 3 months ago

The problem might be the way your client application is invoking the smart contract. You need to explicitly request the correct contract within the chaincode package, for example:

const assetTransfer = network.getContract("basic", "AssetTransferContract");
const carGarage = network.getContract("basic", "CarGarageContract");

It seems that one of the contracts — for me, the first in the list — is selected as the default contract. The default contract is the one that will be called if you do not explicitly provide the contract name, for example:

const defaultContract = network.getContract("basic");

Note that the two contracts share the containing chaincode's namespace within the ledger so will have visibility of each other's ledger entries. If you want the ledger state of the two smart contracts to be separate, you should deploy them in separate chaincode packages.

@bestbeforetoday This was the issue. This solved my issue. Thank you.

I have a suggestion as well. It was very hard to find this information in the community. I think we need to include this information in the documentation.

bestbeforetoday commented 3 months ago

@ajiths10 Which bits of information were missing for you? The client application side is documented in the API documentation:

It seems that you discovered how to define multiple contracts OK. Again, this is described in the API documentation:

ajiths10 commented 3 months ago

@ajiths10 Which bits of information were missing for you? The client application side is documented in the API documentation:

It seems that you discovered how to define multiple contracts OK. Again, this is described in the API documentation:

I never thought it was on the client side. Anyway, thanks for the support :+1: . The issue is resolved, so I'm closing this issue.