2

I have instantiated a sample NodeJS chaincode from fabric-samples marbles02 all the invoke and query functions are working fine but when i was trying to query this function queryMarblesWithPagination it gives me this error:

Error: endorsement failure during query. response: status:500 message:"transaction returned with failure: TypeError: stub.GetQueryResultWithPagination is not a function"

and my chaincode logs are:

Args: ["queryMarblesWithPagination","{\"selector\":{\"owner\":\"tom\"}}","3",""]
{ fcn: 'queryMarblesWithPagination',
  params: [ '{"selector":{"owner":"tom"}}', '3', '' ] }
TypeError: stub.GetQueryResultWithPagination is not a function
    at queryMarblesWithPagination (/usr/local/src/marbles_chaincode.js:468:47)
    at Chaincode.Invoke (/usr/local/src/marbles_chaincode.js:55:27)
    at handleMessage (/usr/local/src/node_modules/fabric-shim/lib/handler.js:636:47)
    at ChaincodeSupportClient.handleTransaction (/usr/local/src/node_modules/fabric-shim/lib/handler.js:361:9)
    at ClientDuplexStream.<anonymous> (/usr/local/src/node_modules/fabric-shim/lib/handler.js:301:30)
    at emitOne (events.js:116:13)
    at ClientDuplexStream.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at ClientDuplexStream.Readable.push (_stream_readable.js:208:10)
2019-08-29T08:01:17.786Z error [shim:lib/handler.js]                              [mychannel-d8dd2e62] Calling chaincode Invoke() returned error response [TypeError: stub.GetQueryResultWithPagination is not a function]. Sending ERROR message back to peer  
Paul O'Mahony
  • 6,740
  • 1
  • 10
  • 15
Trinayan
  • 867
  • 6
  • 15

3 Answers3

1

I think there is a "typo" in the sample - the function name should start with a lowercase g - getQueryResultWithPagination

R Thatcher
  • 5,550
  • 1
  • 7
  • 15
1

What i saw in stub.js is that the function name starts with small g rather captial G. So instead of calling stub.GetQueryResultWithPagination you should try stub.getQueryResultWithPagination.This should solve your error .

Adarsha Jha
  • 1,782
  • 2
  • 15
  • 37
1

Folks already answered, but I think below link may help you in future

there is a golang interface for hyperledger fabric shim, you can find all the available methods

https://github.com/hyperledger/fabric/blob/master/core/chaincode/shim/interfaces.go

Narendranath Reddy
  • 3,833
  • 3
  • 13
  • 32
  • Thanks for the reference but the problem is in Node chaincode of the samples while in golang its defined properly. – Trinayan Aug 30 '19 at 06:13
  • Oh, Gotcha i. missed the NodeJS word, so you are talking about NodeJS chain code. One thing is in Node we use to write function names with camel case but in go interfaces, methods Capitalize !! – Narendranath Reddy Aug 30 '19 at 06:20