When we use web3.eth.getPastLogs it returns topic and data properties together with rest data. Does it possible to retrieve event args parsing just data and topic as filter? Without to make additional request to node like myContract.getPastEvents?

The reason to use such approach is to avoid additional requests to remote Ethereum node. So the goal to fetch events from multiple contracts by one request.

For example

    fromBlock: 'latest',
    toBlock: 'latest',
    address: [
        ... // multiple contract addresses here
         web3.utils.sha3('Transfer(address,address,uint256)') // or uint ?

So how to parse returned result where data property converts to human readable event args format?


data: String - contains one or more 32 Bytes non-indexed arguments of the log.

topics: Array of Strings - Array of 0 to 4 32 Bytes DATA of indexed log arguments. (In solidity: The first topic is the hash of the signature of the event (e.g. Deposit(address,bytes32,uint256)), except if you declared the event with the anonymous specifier.)

Let's consider event Transfer with definition:

event Transfer(address indexed from, address indexed to, uint256 value);

signature Transfer(address,address,uint256)

signature hash sha3('Transfer(address,address,uint256)') = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef


Mint 10 tokens to account 0xf1DFA31Bd1B4aC386868ced5f2b7e224A347aC8f, mint emits Transfer event from 0x0000000000000000000000000000000000000000 to 0xf1DFA31Bd1B4aC386868ced5f2b7e224A347aC8f

    "address": "0x6853168f0985fc08e6dc49f4e3a37f52ae98951b",
    "blockHash": "0xfce1ce22fecfe019fb28ccdc5bfc3477ebc5e6f7d84bbd6687b25d386a0600a6",
    "blockNumber": 4291221,
    "data": "0x000000000000000000000000000000000000000000000000000000000000000a",  // 3rd non-indexed parameter
    "logIndex": 6,
    "removed": false,
    "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",  // signature
        "0x0000000000000000000000000000000000000000000000000000000000000000",  // 1st indexed parameter
        "0x000000000000000000000000f1dfa31bd1b4ac386868ced5f2b7e224a347ac8f"   // 2nd indexed parameter
    "transactionHash": "0x7cee18327143b52832ea13deba7c4397ed8d63b60811567cdf7b217a40b1b410",
    "transactionIndex": 9

All parameters in hex format

parseInt('0x000000000000000000000000000000000000000000000000000000000000000a', 16) = 10

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.