title: Flexible input (variadic function) in Fabric Chaincode possible?
body: <p>I'm trying to create a Hyperledger Fabric chaincode function/method which accepts an indeterminate number of inputs (i.e. variadic function).</p>
  <p>I'm working in Go.</p>
  <p>Here is what I have:</p>
  <pre><code> 38 type Prod struct {
   39   ProdID string `json:&quot;prodID&quot;`
   40   Attributes []string `json:&quot;attributes&quot;`
   41 }
  
  420 func (s *SmartContract) Ver2(ctx contractapi.TransactionContextInterface, prodID string, input...string) error {
  421   //create Prod struct
  422   var p Prod
  423   //set values based on input:
  424   p.ProdID = prodID
  425   p.Attributes = make([]string,len(input))
  426   for i:=0; i&lt;len(input); i++ {
  427     p.Attributes[i]=input[i]
  428   }
  429   //convert Go struct into JSON format
  430   assetJSON, err := json.Marshal(p)
  431   if err != nil {
  432     return fmt.Errorf(&quot;Problem encountered during marshaling: %v\n&quot;, err)
  433   } 
  434   //write data to ledger
  435   return ctx.GetStub().PutState(prodID, assetJSON)
  436 }
  </code></pre>
  <p>When I try to call this chaincode with the following code</p>
  <pre><code>peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile /home/hans/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n scm -c '{&quot;Args&quot;:[&quot;Ver2&quot;,&quot;BB&quot;,&quot;ok&quot;,&quot;maybe&quot;,&quot;test&quot;]}'
  </code></pre>
  <p>I get this error:</p>
  <pre><code>Error: endorsement failure during invoke. response: status:500 message:&quot;Error managing parameter param1. Conversion error. Value ok was not passed in expected format []string&quot;
  </code></pre>
  <p>Is there a problem with my code or is this a limitation of the Fabric api that I am using?<br />
  I've tried searching online, but haven't stumbled on any relevant discussion or documentation around variadic functions in chaincode.</p>
  <p>I got a similar (albeit non-chaincode) working version here: <a href="https://play.golang.org/p/-7NX8-Uf88p" rel="nofollow noreferrer">https://play.golang.org/p/-7NX8-Uf88p</a></p>
  <p>For what it's worth, I succeeded in making a variadic helper function which I can call from another chaincode function, but the variadic input cannot be modified without updating the chaincode.  (So not very useful to me.)</p>
  <p>For reference, those two functions are listed below:</p>
  <pre><code>394 func (s *Prod) VeriTest(ctx contractapi.TransactionContextInterface, prodID string, attr ...string) { 
  395   s.ProdID = prodID
  396   s.Attributes = make([]string, len(attr))
  397   for i:=0; i&lt;len(attr); i++ { 
  398     s.Attributes[i]=attr[i]
  399   } 
  400 }
  401 
  402 //Ver: Proof of Concept - linked to VeriTest above
  403 func (s *SmartContract) Ver(ctx contractapi.TransactionContextInterface) error { 
  404   //create Prod struct
  405   var p Prod
  406   //call VeriTest on Prod
  407   p.VeriTest(ctx,&quot;AA&quot;,&quot;test&quot;,&quot;string&quot;,&quot;five&quot;)
  408   //convert Go struct into JSON format
  409   assetJSON, err := json.Marshal(p)
  410   if err != nil { 
  411     return err
  412   } 
  413   //write data to ledger
  414   return ctx.GetStub().PutState(&quot;AA&quot;, assetJSON)
  415 }
  </code></pre>