10

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:

"0x000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000078f1859239df5000000000000000000000000047f606fd5b2baa5f5c6c4ab8958e45cb6b054b70000000000000000000000001c7e7127a73162b134ab807c3e9f226cd5fd112800000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000084032326c6f6f7073000000000000000000000000000000000000000000000000"

mesqueeb
  • 555
  • 8
  • 21

2 Answers2

9

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.

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
MaKue
  • 246
  • 1
  • 2
1

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

Rader
  • 41
  • 3