1

The following link describes some of how the function web3.eth.filter(...) works:

https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethfilter

What I would like to do is get a list of the transaction objects of all transactions happening to one account. Currently I have the following code:

var options = {
  fromBlock: "pending",
  toBlock: "latest",
  address: "0xab1323fe3234234234fa34324324234af3423432",
};
var filter = web3.eth.filter(options);

filter.watch(function(error, result){
  if (!error)
    console.log(result);
});

Question:

Is the previous code doing what I want? This is what I want it to do:

  • Whenever the App starts running, so does geth and all the blocks that are added to the blockchain start getting filtered, and when a match for the address in the options object is found, it saves that log. though I'm not sure if it's whenever that address is found either being sent to or if it's when it is the sender.

  • I don't want any blocks to be skipped. But the previous javascript code then has to be applied to geth, and in order for that to happen, geth must be running before the filter is applied, so doesn't that mean some of the blocks are skipped before the filter is applied?


EDITED:

I went to the website https://etherscan.io/txs?block=4067373

and with that information choose the following address (third in line) to test on:

0x25f000254108a104A7127B5a5697cb3C12643e62

And the following code was tested:

var options = {
  fromBlock: 4067373,
  toBlock: 4067373,
  address: "0x25f000254108a104A7127B5a5697cb3C12643e62",
};
var filter = web3.eth.filter(options);

filter.get(function(error, result){
  if (!error)
    console.log(JSON.stringify(result, null, 2));
});

I also did another test with the options object being:

var options = {
  fromBlock: 4067372,
  toBlock: 4067374,
  address: "0x25f000254108a104A7127B5a5697cb3C12643e62",
};

In both cases, the result was an empty array:

[]

Question:

Is there anything being done wrong above? I expected to get some values in the result array and I don't know why it is empty.

1 Answer 1

6

From the documentation watch will only look for state changes, i.e. only new blocks added from the last time geth was running will be reported.

We found it somewhat unreliable, if there was a chain reorganization some events were not fired although the transaction was incorporated in the blockchain, or they were fired but the transaction was removed in the reorganization.

Another problem is this will not work for "internal transactions", i.e. if a contract makes a transfer to the address being monitored it will not generate a result.

You can always retrieve the events in a given range with get

var previousBlock = 1000;
var options = {
  fromBlock: previousBlock,
  toBlock: previousBlock + 100,
  address: "0xab1323fe3234234234fa34324324234af3423432",
};

var filter = web3.eth.filter(options);

filter.get(function(error, result) {
    if (!error) {
        console.log(result);
    }
});
3
  • Hey Ismael thank you for the response! I tried out your answer, and I edited my question to include the attempt. I believe things are getting closer though I did get an issue. I wrote the situation above, would you happen to know what went wrong?
    – Webeng
    Jul 24, 2017 at 15:51
  • I can't test right now, if you have a new question then you are better creation a new one, because people tend to read unanswered first.
    – Ismael
    Jul 24, 2017 at 16:43
  • I understand. I was trying to test out your solution for it since it seems really good :). I made a new question on it here as you suggested: ethereum.stackexchange.com/questions/22954/…
    – Webeng
    Jul 24, 2017 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.