Warm tip: This article is reproduced from serverfault.com, please click

Error: No valid responses from any peers. Failed to execute transaction could not launch chaincode

发布于 2020-12-08 18:41:44

I am trying to run the app.js file in the provided asset-transfer-ledger-queries folder with a slight modification.

I made a change to the asset-transfer-ledger-chaincode.js file as shown below:

async CreateAsset(ctx, assetID, color, size, owner, appraisedValue) {
    const exists = await this.AssetExists(ctx, assetID);
    if (exists) {
        throw new Error(`The asset ${assetID} already exists`);
    }

    // ==== Create asset object and marshal to JSON ====
    let asset = {
        docType: 'asset',
        assetID: assetID,
        color: color,
        size: size,
        owner: owner,
        appraisedValue: appraisedValue,
        couponID: assetID,
        value: color,
        expiration: size,
        user: sha256(owner),
        uuid: uuid.v5(),
        redeemed: false
    };

basically I just added some properties to the asset object.

After updating the chaincode and running node app.js, I get the following error:

 --> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-08T18:22:27.975Z - 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 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
    peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
******** initLedger failed :: Error: No valid responses from any peers. Errors:
    peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1
    peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 3832a02eeafd57382fb4810bc263d41693764f0d8cb76c27e5613c359b14d42f: could not launch chaincode ledger_1.0:7230409065bcd9da163bc285287935a7d6a3799c99ee59b8a77c93883b607bdb: chaincode registration failed: container exited with 1

It works fine if I don't make any changes to the chaincode file. Does anyone know what I can do?

Questioner
Jasmine Wong
Viewed
22
myeongkil kim 2020-12-12 11:21:41

I tried to reproduce your situation.

# fabric-samples/test-network
./network.sh down
./network.sh up createChannel -c mychannel -ca
./network.sh deployCC -ccn ledger -ccl javascript
# fabric-samples/asset-transfer-ledger-queries/application-javascript
node -v 
# v12.13.1
npm install
node app.js

You can also, see error logs in chaincode container

# check <your_chaincode_container_name>
docker ps -a

# view logs
docker logs <your_chaincode_container_name> 

1. Import library [chaincode.js]

#[ERROR CODE] - `node app.js`
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-10T00:53:48.061Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
    peer=peer0.org2.example.com:9051, status=500, message=error in simulation: transaction returned with failure: ReferenceError: sha256 is not defined
    peer=peer0.org1.example.com:7051, status=500, message=error in simulation: transaction returned with failure: ReferenceError: sha256 is not defined

do it

# asset_transfer_ledger_chaincode.js

const {Contract} = require('fabric-contract-api');
const sha256 = require('sha256');         // added
const uuid = require('uuid');             // added
# package.json
    "dependencies": {
        "fabric-contract-api": "^2.0.0",
        "fabric-shim": "^2.0.0",    // added ','
        "sha256": "^0.2.0",         // added
        "uuid": "^8.3.2"            // added
    }

2. Fix wrong module code

#[ERROR CODE] - `node app.js`
--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
2020-12-10T01:03:27.583Z - 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 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
    peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
******** initLedger failed :: Error: No valid responses from any peers. Errors:
    peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1
    peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 62c19fbb84394ba1de399745c46f781078134b84de6b3d73419b9f65c5fa692b: could not launch chaincode ledger_1.0:5303ef138ca9cdb054cd3d814835fffca2706aa0c8e387611b93e4d6d1773742: chaincode registration failed: container exited with 1

uuid.v4() Create a version 4 (random) UUID
uuid.v5() Create a version 5 (namespace w/ SHA-1) UUID uuid.v5() requires input parameters

do it

# asset_transfer_ledger_chaincode.js

        // ==== Create asset object and marshal to JSON ====
         let asset = {
            docType: 'asset',
            assetID: assetID,
            color: color,
            size: size,
            owner: owner,
            appraisedValue: appraisedValue,
            couponID: assetID,
            value: color,
            expiration: size,
            user: sha256(owner),
            uuid: uuid.v5('Hello, World!', '1b671a64-40d5-491e-99b0-da01ff1f3341'), // modified
            redeemed: false
        };

3. Result (Solved)

# fabric-samples/asset-transfer-ledger-queries/application-javascript
# node app.js

Loaded the network configuration located at /Users/kmk/Project/src/github.com/hyperledger/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.json
Built a CA Client named ca-org1
Built a file system wallet at /Users/kmk/Project/src/github.com/hyperledger/fabric-samples/asset-transfer-ledger-queries/application-javascript/wallet
Successfully enrolled admin user and imported it into the wallet
Successfully registered and enrolled user appUser and imported it into the wallet

--> Submit Transaction: InitLedger, function creates the initial set of assets on the ledger
*** Result: committed
*** application ending