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()
           if (err)
    return false;

It returns in my browser's console:

function checkLastCustomerInvoices()
Array [ "0x0000000000000000000000000000000000000000000000000000000000000020" ]

So the result returned by JSON-RPC seems to be a string that concatenates in some way :


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 ?


  • I guess 32 is for bytes32 : size of each array element.. – humhum Jan 30 at 13:55

Not sure how to do this from a browser, but from a (client-side) node script, you can do:

const web3_eth_abi = require("web3-eth-abi");
const array = web3_eth_abi.decodeParameter("uint256[]", yourReturnedObject.result);
  • Thanks, this could be a trail, but I'm looking for a solution in JSON-RPC and don't know if I can use web3.js on on remote ethereum client side. The documentation (github.com/ethereum/wiki/wiki/JSON-RPC#returns-24) states that any call is returned as string of DATA without any further information on its formatting. So I guess there must be some hidden documentation somewhere, but I'm unable to fin it... – humhum Jan 30 at 13:42
  • @humhum: Yes, but you can take that string and convert it into an object via obj = JSON.parse(str). – goodvibration Jan 30 at 14:12
  • Don't get it : obj=JSON.parse(str) will make an object from a string containing JSON syntax. It won't in any case create an object from 'result' whose formatting comes from JSON-RPC … – humhum Jan 30 at 15:18
  • @humhum: It should create a JSON object with a result field. – goodvibration Jan 30 at 15:21
  • Yes but it doesn't change the problem: the result object field still contains that string: Proof: In the console: (used elipses instead of real characters to shorten the comment..) >>obj=JSON.parse('{"id":1,"jsonrpc":"2.0","result":"0x ......"}'); Object { id: 1, jsonrpc: "2.0", result: "0x..." } >>obj.result "0x...." – humhum Jan 30 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.