Hyperledger Fabric Error: 2 UNKNOWN: access denied: channel [mychannel] creator org [Org1MSP]

Viewed 1531

I'm trying to interact with the peers from JavaScript and I keep getting

{ Error: 2 UNKNOWN: access denied: channel [mychannel] creator org [Org1MSP]
    at Object.exports.createStatusError (/blockchain-api-js/node_modules/grpc/src/common.js:87:15)
    at Object.onReceiveStatus (/blockchain-api-js/node_modules/grpc/src/client_interceptors.js:1188:28)
    at InterceptingListener._callNext (/blockchain-api-js/node_modules/grpc/src/client_interceptors.js:564:42)
    at InterceptingListener.onReceiveStatus (/blockchain-api-js/node_modules/grpc/src/client_interceptors.js:614:8)
    at callback (/blockchain-api-js/node_modules/grpc/src/client_interceptors.js:841:24)
  code: 2,
  metadata: [Object],
  details: 'access denied: channel [mychannel] creator org [Org1MSP]' }

I'm using the fabric-ca sample and I was able to execute transactions from cli and from cli through run-fabric.sh but I can't seem to do that from JS, I've created a new user and set the client and cert with client.setTlsClientCertAndKey(cert, key);, I even tried giving the admin cert and key from /data/orgs/org1/admin/msp/signcerts, /data/orgs/org1/admin/msp/admincerts and /data/orgs/org1/admin/msp/keystore as well as the ones from /data/tls/ but with no luck And this is the portion of the code I use:

var channel = this.client.newChannel('mychannel')

    let serverCert = fs.readFileSync('/data/org0-ca-chain.pem');

    channel.addOrderer(
        this.client.newOrderer(
            config.orderers['orderer1-org0'].url,
            {
                pem: Buffer.from(serverCert).toString()
            }
        )
    );

    serverCert = fs.readFileSync('/data/org1-ca-chain.pem');

    const peer1 = this.client.newPeer(
        config.peers['peer1-org1'].url,
        {
            pem: Buffer.from(serverCert).toString()
        }
    );
    channel.addPeer(peer1);
    this.eventhubs = []
    this.eventhubs.push(channel.newChannelEventHub(peer1));

    serverCert = fs.readFileSync('/data/org2-ca-chain.pem');

    const peer2 = this.client.newPeer(
        config.peers['peer1-org2'].url,
        {
            'pem': Buffer.from(serverCert).toString()
        }
    );
    channel.addPeer(peer2);
    this.eventhubs.push(channel.newChannelEventHub(peer2));
    this.channel = channel;
    console.log(this.channel)

    return this.channel.sendTransactionProposal(request);

Is there something wrong with my code or the way I do it? Can someone tell me what I am doing wrong? I've seen a few similar questions but those happened when composer was used mostly and I couldn't fix my problem with the answers from there,

2 Answers

You'd better check the user context of client I think.

user context has mspID. check whether mspId is Org1MSP or not.

The error could be because of the Certificates to sign the transaction.Double check your certificate received from CA and also checked the certificates and path used inside the docker container of peers.

Related