1

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.

Webeng
  • 895
  • 2
  • 12
  • 26

1 Answers1

7

When I started working on Ethereum even I was having issues similar to this and I learned the hard way. I will share what I learned from my mistakes and hope you don't end up doing the same.

Answer to your 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.

I think you got the wrong understanding of FILTER. You're using the topic filter API, which filters for events emitted by contracts; thus, only contracts are going to show up in that.

As, when I tried your code (on my TESTNET) for a random address:

var options = {
 fromBlock: 1535000,
 toBlock: 1535104,
 address: "0x76e0bb92b6f8d431af2fe1bafd304eb832241619" 
};

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

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

The result from this was:

[]

But when I replace the value of "address" key, with a contract address and add a from address (i.e. from which contract functions were invoked)

CODE:

var options = {
    fromBlock: 1535000,
    toBlock: 1535104,
    address: "0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9", //CONTRACT ADDR
    from: "0x76e0bb92b6f8d431af2fe1bafd304eb832241619" //WALLET ADDR
};

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

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

RESULT:

{
  "address": "0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9",
  "topics": [
    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
    "0x00000000000000000000000076e0bb92b6f8d431af2fe1bafd304eb832241619",
    "0x0000000000000000000000002b3425ce986f9f0f599758f4fb33158ca671e83e"
  ],
  "data": "0x0000000000000000000000000000000000000000000000000000000000000001",
  "blockNumber": 1535088,
  "transactionHash": "0xf523285b652163f50f1d19ca08951f38b4bfe099d721a6e6d80ff7fd03a171eb",
  "transactionIndex": 4,
  "blockHash": "0x27a29bf153b302a5e8f24415ed1f2fac1829e845746bed9f3098f0b40cd232a5",
  "logIndex": 1,
  "removed": false
}
{
  "address": "0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9",
  "topics": [
    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
    "0x00000000000000000000000076e0bb92b6f8d431af2fe1bafd304eb832241619",
    "0x0000000000000000000000002b3425ce986f9f0f599758f4fb33158ca671e83e"
  ],
  "data": "0x0000000000000000000000000000000000000000000000000000000000000001",
  "blockNumber": 1535104,
  "transactionHash": "0x14632d129a6aac7365483a3000470ece443a19a73f242cba1f1944f78889a677",
  "transactionIndex": 7,
  "blockHash": "0x34ee516310a59407712455ec87bd76046a1e68f5c631dc8e6b4bb903b8c92834",
  "logIndex": 6,
  "removed": false
}

The are all transactions done from that address (0x76e0bb92b6f8d431af2fe1bafd304eb832241619) on Contract (0x5c99dadde01ce61ab5b5536d566bf41ecd17e3a9) between blocks 1535000-1535104.

NOTE:

If you want to get non-contractual transactions from the blockchain, you need to examine each block for transactions which happened in that blog and then get a transaction details using web3 API. This Link (Common useful JavaScript snippets for geth) has this section Script To Find Transactions To/From An Account

The above link wont help you to know the internal transactions which happen inside a contract, here is the link to same . Hopefully this helps you.

farhankhwaja
  • 473
  • 2
  • 12
  • I am trying to find out the incoming transactions on a particular account.It is not related to any contract.So I have modified the Filter as follows var filter = web3.eth.filter({fromBlock: 1, toBlock: 'latest',to: '0x5f677ba7b786411f406a314ca339783ad8d21acc'}); filter.get(function(error, result){ console.log(error, result); }); – Crissi Mariam Robert Nov 01 '17 at 05:33
  • The above filter displays the same result as other filters.How can I modify the filter for my requirement? – Crissi Mariam Robert Nov 01 '17 at 05:34
  • i would recommend, if the filter doesnt work for you, try accessing all transactions in the block and then check if the transaction belongs to you or no. – farhankhwaja Jul 21 '18 at 00:29