0

I have the following code:

var filter = web3.eth.filter({
    fromBlock:4076955, 
    toBlock:"latest",
    address:"0x0123456789012345678901234567890123456789"
});

filter.get(function(error,logs){
  if (!error) {
    console.log("Found block " + logs.blockNumber);
    console.log(JSON.stringify(logs,null,2));
  }
}

and when I run the code, I get:

Found block undefined
[]

I would have expected to get a number for logs.blockNumber and an object as the return value (source: https://github.com/ethereum/wiki/wiki/JavaScript-API#watch-callback-return-value)

Question: Why might I not be getting the expected result?

0

Perhaps, the issue is because filter.get() returns logs data, only if web3.eth.filter is initialized before the transactions you are looking are appeared.

More info in this issue.

  • oh you mean only if the transactions haven't been added to the blockchain yet? Also if I change the toBlock: 'latest' to toBlock: 4076956 I get the same result. – Webeng Jul 26 '17 at 16:45
  • yes, it's not clear from docs, but, seems, you can listen only that transactions which were born after you set filter with web3.eth.filter – Viktor Baranov Jul 26 '17 at 17:05
  • hmmm, but I was told that filter.watch was for listening, while filter.get was for getting from blocks. Here: ethereum.stackexchange.com/questions/21694/… – Webeng Jul 26 '17 at 17:13
0

I think this is because the results passed to the callback for filter.get are an array of entries. I can't find any code samples from where I've done this before, but I'm pretty sure logs in your callback is an array of blocks or logs, not just a single one. Try just passing console.log.bind(console) to filter.get, to see what the raw values are?

  • Hi thanks for the response! Where in the code should I include the console.log.bind(console)? – Webeng Jul 28 '17 at 16:13
  • Instead of filter.get(function...), do filter.get(console.log.bind(console)) – DeviateFish Jul 29 '17 at 6:52

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.