I was able to use the EtherScan api to get an array with event logs. Now I need to read from the data stored inside.

The event data exists out of: uint256, uint256, uint256, address, address, string.

I can do the following web3 function: web3.utils.hexToNumber(hex) for the uint's and hexToUtf8 for the strings.

However I have 2 problems:

  1. There's no web3 function hexToAddress. How can I do this?
  2. I'm not sure how to split the event data with a web3 function or other method.

This is an example of the event data:



You could also use web3 directly using the web3.eth.abi.decodeParameters(typesArray, hexString) function:

In your case it would look like this:

web3.eth.abi.decodeParameters(['uint256', 'uint256', 'uint256', 'address', 'address', 'string'], '0x000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000078f1859239df5000000000000000000000000047f606fd5b2baa5f5c6c4ab8958e45cb6b054b70000000000000000000000001c7e7127a73162b134ab807c3e9f226cd5fd112800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000084032326c6f6f7073000000000000000000000000000000000000000000000000')

Read more at https://web3js.readthedocs.io/en/1.0/web3-eth-abi.html#decodeparameters.

  • I think the second parameter (the data) needs to be a string?
    – mesqueeb
    May 25 '18 at 8:59
  • And also, the first parameters is an array of strings. If you edit that I'll mark it as correct! Thanks so much btw!!!
    – mesqueeb
    May 25 '18 at 9:00
  • BTW, I have this error in node: throw new Error('Couldn\'t decode '+ name +' from ABI: 0x'+ param.rawValue); any idea?
    – mesqueeb
    May 25 '18 at 9:14

there is a lib for event log parsing from ConsenSys, the abi-decoder

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.