I tried to deploy a chaincode to test-network(fabric sample/hyperledger fabric 2.2). I followed these steps mentioned in documentations https://hyperledger-fabric.readthedocs.io/en/release-2.0/deploy_chaincode.html.
this is the smart contract ::
'use strict';
const { Contract } = require('fabric-contract-api');
class RegisterUser extends Contract {
async initLedger(ctx) {
console.info('============= START : Initialize Ledger ===========');
const users = [
{
UserId: 'admin',
FirstName : 'network',
LastName : 'supervisor',
BillFold : 'none',
},
];
for (let i = 0; i < users.length; i++) {
users[i].docType = 'user';
await ctx.stub.putState('USER' + i, Buffer.from(JSON.stringify(users[i])));
console.info('Added <--> ', users[i]);
}
console.info('============= END : Initialize Ledger ===========');
}
async queryUser(ctx, userId) {
const userAsBytes = await ctx.stub.getState(userId); e
if (!userAsBytes || userAsBytes.length === 0) {
throw new Error(`${userId} does not exist`);
}
console.log(userAsBytes.toString());
return userAsBytes.toString();
}
async createUser(ctx, userId, first_name, last_name,billfoldId) {
console.info('============= START : Create User ===========');
const user = {
UserId: userId,
doctype : 'user',
FirstName : first_name,
LastName : last_name,
BillFold : billfoldId,
};
await ctx.stub.putState(userId, Buffer.from(JSON.stringify(user)));
console.info('============= END : Create User ===========');
}
} module.exports = RegisterUser;
Runing a node application that implement the chaincode gives this error:
2021-03-30T10:55:42.115Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 112a4c6dbf49bdea7aaa4ca5e24a03eeebf89a0989d278319cf6aecae061d310: could not launch chaincode usercontract_1.0:995a82a19e6a5e211d6ca52dff9eccb5cfd79249418657e0c9f599c9b1ffe9f0: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 112a4c6dbf49bdea7aaa4ca5e24a03eeebf89a0989d278319cf6aecae061d310: could not launch chaincode usercontract_1.0:995a82a19e6a5e211d6ca52dff9eccb5cfd79249418657e0c9f599c9b1ffe9f0: chaincode registration failed: container exited with 1