Search code examples
hyperledger-fabrichyperledger-chaincode

Pass array data to chaincode in hyperledger fabric


I have modified fabcar example to store my own data. I have to save json data into the blocks. Some of the object properties are strings and array. But i can't able to pass the array to the chaincode.

Here is my json data

{
key : '5e57b8dbb9b30e3575f45d75',
Thp_stRpPmp: '0',
Thp_stSprPmp: '0',
Thp_stArrFans: [0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,0],
Thp_bSpry: 'false',
}

While trying to submit transaction i am facing error like this.

error inside await Error: Transaction arguments must be strings:     

How to resolve this?


Solution

  • As the error says, arguments can only be strings.

    You can send your arguments marshaled as an string and unmarshal them in your chaincode.

    When working with complex data, I usually send an only JSON marshaled string that I unmarshal in my chaincode. You lose in performance with un/marshaling process, but you win in maintainability when suitably matched to your program models.