4

I have structure of event in my Solidity code like event test(address investor, uint256 priceinWei).

I make a request to etherscan to get all logs from contract on specific addres and get

{  
   'address':'...',
   'topics':[  
      '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
      '0x0000000000000000000000001111111111111111111111111111111111111111',
      '0x000000000000000000000000409fefe0212a75d8c117ac834123d462bce9635c'
   ],
   'data':'0x000000000000000000000000000000000000000000000012f94bfef30bf32b8d',
   'blockNumber':'...',
   'timeStamp':'....',
   'gasPrice':'0x4a817c800',
   'gasUsed':'0x182b7',
   'logIndex':'0x8',
   'transactionHash':'...',
   'transactionIndex':'0xc'
}

Question: How can I get address and price from it. Should I decode "data"? Instead ... I of course got values, just don't want to show it.

1

You can create a reference testEvent to the event using

    var testEvent = Contract.test({}, {fromBlock: startBlockNo, toBlock: 'latest'});

and then use watch or get to on this reference to retrieve the events:

testEvent.watch(function(error, result){
    if(!error) {
        // do what you want to do with the event data
    }
});

or

testEvent.get(function(error, result){
    if(!error) {
        // do what you want to do with the event data
    }
});

Within the if(!error) {...}part you can access the data of the event from your question using result.args.investerand result.args.priceinWei.

The difference between watch and get is that getwill only give you past events, while watch will get you past events and watching for new ones.

  • 1
    can't find it in web3 python. more accurately: yes, I can set listener but, don't get decoded info – Averin Maxim Nov 22 '17 at 12:16

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.