I have written data to a contract using sendRawTransaction, and am trying to fetch it using web3.eth.call for the function :
function checkRecord(uint id, bytes email) constant returns (uint id2, bytes email2, bytes hash) {..}

I create call data as
var callData = contract.checkRecord.getData(id, email)
to get

and fetch result as
result = web3.eth.call({'to': address, 'from': account, 'data': callData})

where result is

How do i decode the result back to (uint, bytes, bytes) ?


you can use web3 built-in functionality:

web3.eth.abi.decodeParameters(typesArray, hexString);

see link


As the web3 documentation points out web3.eth.call returns a String, which is the returned data of the call, e.g. a codes functions return value. In your case the result string contains a uint (which is an alias for uint256) and two dynamically-sized byte arrays.

Split the result into 32-byte chunks and then apply a toAscii(hexString) function on the chunks.

With this method you'll get that the uint is the number 2 padded with zeroes, it looks like this: 0x0000000000000000000000000000000000000000000000000000000000000002. The first byte array is {96,160,21,matgeo.2008@gmail.com}. The second byte array contains only zeros.

  • toAscii is deprecated. Use hexToAscii in web3 v1. web3.utils.hexToAscii(0x....) – sunwarri0r Jul 16 '18 at 9:03

The easiest way to to use "abi-decoder". I forked the repository and created index.html for easy usage.

You can download and use it from: https://github.com/Muhammad-Altabba/abi-decoder (you can later check it at https://github.com/ConsenSys/abi-decoder once they will accept my Pull-Request)

To download and run using NPM:

npm install abi-decoder
bower install abi-decoder

Then download https://github.com/Muhammad-Altabba/abi-decoder/index.html to the same directory. Then open the file "index.html" in browser.

You will get:

abi-decoder index.html

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.