I have a function in my Solidity contract whose prototype is:
function checkLastCustomerInvoices() public view returns (bytes32 [] memory)
When I call it from the Truffle console it returns an array of elements, namely :
truffle(development)> myContractInstance.checkLastCustomerInvoices(); [ '0x0000000000000000000000000000000000000000000000000000657567656f74', '0x0000000000000000000000000000000000000000000000000000656e61756c74', '0x0000000000000000000000000000000000000000000000000065726365646573' ]
When I call it from the browser with JSON-RPC, with the JavaScript code :
function checkLastCustomerInvoices()
{
myContractInstance.checkLastCustomerInvoices(function(err,res){
if (err)
console.log(err);
else
{
console.log(res);
}
}
);
return false;
}
It returns in my browser's console:
function checkLastCustomerInvoices() Array [ "0x0000000000000000000000000000000000000000000000000000000000000020" ] {"id":1,"jsonrpc":"2.0","result":"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000657567656f740000000000000000000000000000000000000000000000000000656e61756c740000000000000000000000000000000000000000000000000065726365646573"}
So the result returned by JSON-RPC seems to be a string that concatenates in some way :
0x 0000000000000000000000000000000000000000000000000000000000000020 0000000000000000000000000000000000000000000000000000000000000003 0000000000000000000000000000000000000000000000000000657567656f74 0000000000000000000000000000000000000000000000000000656e61756c74 0000000000000000000000000000000000000000000000000065726365646573
Besides the 0x, The first line is 32 (what use ?) The second line the number of elements and the 3 other lines my array elements.
Where is described this encoding ? Is there a standard JavaScript method used to parse this string to a JavaScript array ?
Thanks