How to retrieve hyperledger success payload via nodejs client

Viewed 376

Given an implemented chaincode stub invoke function:

func (lc *chaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
        return shim.Success([]byte("{\"car\":\"audi\"}"))
    }
}

How does one receive the shim.Success payload via NodeJS?

Upon reviewing the results after running transaction proposal: channel.sendTransactionProposal(proposalRequest).then((results) => { console.log(results); // very complex undocumented object });

The documentation is lacking and the sample scenarios are a bit too complex, therefore I thought it would be useful to have a simple answer on SO

1 Answers

The channel.sendTransactionProposal to ledger actually generates a Response object which can be accessed as described below:

results[0][0].response.payload.toString('utf-8');

Related