简体   繁体   中英

Hyperledger fabric error while deploying a custom chaincode

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

During installation, a docker container would be spun off based on your chaincode language. Monitor this docker container's logs and you'll see the reason for failure. All the best. If you are running all this on windows, then docker desktop would give you realtime view of the containers that are UP and with mouse clicks you can see the docker container logs too.

Without monitoring the docker container logs it is hard to tell why something is failing. All the best.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM