1

At this point I was unable to find clear examples on how to use getTransient in Node.js. Maybe you can help me just with the right link.

Assume I have a client application in Node.js that submits something like:

const privatePayload = new Buffer(JSON.stringify({"Args":args})).toString('base64');
const result = await contract.createTransaction(func).setTransient({"privatePayload" : privatePayload}).submit();

In my Node.js chaincode I have something like this:

var MAP = ctx.stub.getTransient();
...

What I see, is that data comes in form of

{ privatePayload:
   { key: 'privatePayload'
     value: 
       ByteBuffer {
buffer: <Buffer 0a c1 .... >,
offset: ...,
...
}

I access this buffer, decode it and see, that it contains not only my payload as a string, but also name of OrgMSP, CERTIFICATE, channel information etc all in one block. My payload is at the end.

Is there a ready to use API to just access my payload? What is the actual format of this buffer?

Fedor Petrov
  • 990
  • 9
  • 19
  • I am facing an issue i tried the exact same code but the issue is when i try let transientData = await ctx.stub.getTransient(); from chaincode I am getting am empty response. My nodeJS client code is const privatePayload = Buffer.from(JSON.stringify(args)) const result = await contract.createTransaction(functionName).setTransient({"privatePayload" : privatePayload}).submit(); Is there anything more i need to add – GPC Nov 05 '20 at 13:51
  • See answer below. – Fedor Petrov Nov 05 '20 at 15:02

2 Answers2

1

Try chaincodeStub.getTransient().get('key').toString('utf8')

1

And you don't have to use "await" with getTransient() since the function already returns a map of values. Just something like that would work:

var MAP = ctx.stub.getTransient();
Fedor Petrov
  • 990
  • 9
  • 19