DTZ
DTZ

Reputation: 127

Error at HYPERLEDGER FABRIC while trying to use the chaincode for the test network but running my application

My problem is that i get an Error while trying to use the chaincode for the test-network but running my application instead of the application-javascript provided at fabric-samples/asset-transfer-basic.

The steps that I follow are:

1.  ./network.sh up createChannel -c mychannel -ca
2.  ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
3.  run my application thats is exaclty same with the one provided at docs (fabric-samples/asset-transfer-basic) to InitLedger and they query or update it.

The error I get is the following:

--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger 2021-11-09T15:54:16.248Z - error: [Transaction]: Error: No valid responses from any peers. Errors: ******** FAILED to run the application: Error: No valid responses from any peers. Errors:

The code in my application is exactly the same as the one at docs:

const ccp = buildCCPOrg1();
const caClient = buildCAClient(FabricCAServices, ccp, 'ca.org1.example.com');

const wallet = await buildWallet(Wallets, walletPath);

await enrollAdmin(caClient, wallet, mspOrg1);
await registerAndEnrollUser(caClient, wallet, mspOrg1, org1UserId, 'org1.department1');

const gateway = new Gateway();

await gateway.connect(ccp, {
    wallet,
    identity: org1UserId,
    discovery: { enabled: false, asLocalhost: true } // using asLocalhost as this gateway is using a fabric network deployed locally
});

const network = await gateway.getNetwork(channelName);
const contract = network.getContract(chaincodeName);
await contract.submitTransaction('InitLedger');


Upvotes: 1

Views: 354

Answers (1)

MimoKrok
MimoKrok

Reputation: 121

You have peer discovery disabled in your code, usually, you do it when you specify peers you want to connect to but since you don't do it - the SDK client just didn't know to what peers it should connect so it connected to none of them, got 0 responses and threw an error. So I changed this line from your example:

discovery: { enabled: false, asLocalhost: true }

to:

discovery: { enabled: true, asLocalhost: true }

And it worked.

Upvotes: 2

Related Questions