Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startup dev with arguments for Init #33

Closed
sedacrivity opened this issue May 29, 2018 · 2 comments
Closed

startup dev with arguments for Init #33

sedacrivity opened this issue May 29, 2018 · 2 comments

Comments

@sedacrivity
Copy link

Hi Folks,

First off all .. great stuff you have going here ...
I only just started dabbing my feed in HF and was looking into creating node js chaincode and noticed that the fabric samples example for the startup dev env was only for go ... a search later and I stumbled upon this project ... ( en dan nog van landgenoten ... altijd leuk :-) )

Got a ( potential noob ) question ...

I replicated the standard go example in node js - it uses an Init method which expects arguments so I noticed that this doesn't work when I start up the environment as I did not provide arguments (obviously):

_2018-05-29T15:13:07.144Z ERROR [lib/handler.js] [defaultchannel-2292664a]Calling chaincode Init() returned error response [Incorrect number of arguments. Expecting 2]. Sending ERROR message back to peer_

Is there a way to pass along arguments during start-up or is that intentional by design - perhaps not a good chaincode (coding) practice ? I noticed your 'ChaincodeBase' also assumes there are no arguments ...

Thanks

Steven

@janb87
Copy link
Contributor

janb87 commented Jun 5, 2018

Hi @sedacrivity

In our ChaincodeBase it has no arguments but you could overwrite the function in your implementation and get access to the 'stub' (https://fabric-shim.github.io/ChaincodeStub.html). From the stub you can get to the arguments.

class Chaincode extends ChaincodeBase {
     async Init(stub) {
        const args =  stub.getArgs();
        // ...
    }
}

See https://fabric-shim.github.io/ChaincodeInterface.html.

The Init is only called when instantiating / upgrading chaincode. So it would not run when you invoke or query chaincode. For that you would need to use the 'Invoke' function.

The error you shared seems to come from your chaincode code itself. Would you be able to share your chaincode so I can get some more understanding on what your are trying to do?

@sedacrivity
Copy link
Author

Hi @janb87,

Thanks for your reply and suggestion to overwrite the Init in an own implementation ... that would work fine indeed :-)

The error was indeed coming from the Init implementation within my own chaincode example ( which throws an error when there are no arguments ) - I did not inherit from your implementation ...

I understand that the Init is only executed upon instantiation ... in the Fabric examples it is used to define some attributes already ... but I reckon that is mostly for the sake of the example ... and not necessarely what one would do in a productive implementation ... hence my question on practise ... and it seems you guys didn't find a need either to have arguments in the Init method :-)

Thanks for your reply :-)

@janb87 janb87 closed this as completed Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants