0

I got logs using the following code.

web3.eth.subscribe('logs', {
      address: getLogsAddress,
      fromBlock: '0x' + fromBlock,
      toBlock: 'latest',
      topics: [topics]
  }, function(error, result){
    //   if (!error)
    //       console.log(result);
  })
  .on("connected", function(subscriptionId){
      console.log("subcriptionID === " + subscriptionId);
  })
  .on("data", function(log){
    //   console.log(log);
    // console.log(abiDecoder.decodeLogs(log));
  })
  .on("changed", function(log){
  });

I want to get a decode of this log. How to do this?

3
  • topics are not decodable, the decodable is only the Data field. Topics are the keccak on the Event signature. The ones that your generator of artifacts (whatever it is) have produced. So you only compare topics to existing signatures and decide if this event is the one you are looking for
    – Nulik
    Aug 18 '21 at 0:15
  • actually you are posting the input paramter to subscription for logs, you shoulod provide the list of topics you want to listen for, this is not an output parameter which can be decoded somehow
    – Nulik
    Aug 18 '21 at 0:17
  • I found it. please check it. Thank you for your reply.
    – Alex Weber
    Aug 18 '21 at 2:39
0

I found how to decode topics of the log.

This is my sample code. Please check it.

let item = web3.eth.abi.decodeLog([{
                    type: 'string',
                    name: 'topicsAddress',
                    indexed: true
                },{
                    type: 'address',
                    name: 'from',
                    indexed: true
                },{
                    type: 'address',
                    name: 'to'
                }],
                log.data,
                log.topics
            );
            
            let temp = {};
            temp.from = item.from;
            temp.to = item.to;



I hope to help you.

1
  • yeah, here you decode it because you provided a sample log on the input, and the abi is provided as first parameter
    – Nulik
    Aug 18 '21 at 17:38

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.