Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

eth_newFilter doesn't return any logs #51

Closed
Vypo opened this issue Jul 19, 2020 · 8 comments · Fixed by #61
Closed

eth_newFilter doesn't return any logs #51

Vypo opened this issue Jul 19, 2020 · 8 comments · Fixed by #61
Labels
bug Something isn't working

Comments

@Vypo
Copy link

Vypo commented Jul 19, 2020

Version

git+https://github.com/gakonst/ethers-rs#6f02bb54365f5a786db1214497b9d1ebf8304995

Platform
Linux XPS-15-9570 5.4.0-40-generic #44-Ubuntu SMP Tue Jun 23 00:01:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Description
Using eth_newFilter doesn't seem to return any events. I've never used the ethers.js equivalent, so I suspect it's a problem on my end.

I tried this code:

https://github.com/Vypo/ethers-newfilter

With this contract:

// SPDX-License-Identifier: Unlicense

pragma solidity ^0.6.8;

contract Banana {
    event EatDaBanana(uint256 indexed a0, uint256 indexed a1, uint256 indexed a2);
    
    constructor() public {
        emit EatDaBanana(1, 2, 3);
        selfdestruct(msg.sender);
    }
}

I expected to see this happen: Logs to be printed to the terminal.

Instead, nothing happened.

@Vypo Vypo added the bug Something isn't working label Jul 19, 2020
@gakonst
Copy link
Owner

gakonst commented Aug 1, 2020

Hi, this is not an issue! You are creating a blank filter, which won't find the event! You need to set the topic0 of the filter to be the hash of the event signature and the address to be the address of your contract. Take a look at how this is done in the examples, or the tests

@gakonst gakonst closed this as completed Aug 1, 2020
@Vypo
Copy link
Author

Vypo commented Aug 4, 2020

I tried it again, with the tokio feature rt-core instead of rt-threaded and was able to get results even without adding any criteria to the filter:

The transaction: https://kovan.etherscan.io/tx/0x231617618c603043d6ddb9440df6cf643df63bc51704598ecc36b524d7db9dda

The output from my test program:

    Finished dev [unoptimized + debuginfo] target(s) in 3.49s
     Running `target/debug/ethers-newfilter`
Log: Log {
    address: 0xc42c330a533d4817dd4fda7c16eea68663c3a05f,
    topics: [
        0x72eb3626bdc3a888cf0395b21a914fa3e8975a4012094e9c3410d0f4004ead4f,
        0x0000000000000000000000000000000000000000000000000000000000000001,
        0x0000000000000000000000000000000000000000000000000000000000000002,
        0x0000000000000000000000000000000000000000000000000000000000000003,
    ],
    data: Bytes(
        [],
    ),
    block_hash: Some(
        0x5fd7526a283a82a7edf087b133b0d4971d77c88455b4f596fd2075a4e79448ba,
    ),
    block_number: Some(
        20019373,
    ),
    transaction_hash: Some(
        0x231617618c603043d6ddb9440df6cf643df63bc51704598ecc36b524d7db9dda,
    ),
    transaction_index: Some(
        1,
    ),
    log_index: Some(
        2,
    ),
    transaction_log_index: Some(
        0,
    ),
    log_type: None,
    removed: Some(
        false,
    ),
}

If I flip back to rt-threaded, I don't see any logs at all. Could it have something to do with the tokio runtime?

@roynalnaruto
Copy link
Collaborator

Hi @Vypo I hope this can be useful to you. https://github.com/roynalnaruto/shuffler repository implements streaming a filter. More specifically:

  1. Here are the smart contracts
  2. Here are the Rust bindings for them
  3. Here is the code snippet for a streaming a specific event filter from that smart contract

As discussed on the ethers-rs dev channel, filters are not supported by Infura (except the new blocks filter, which is supported). A localhost ganache instance can be used to test though (have a look at the ERC20 binding and you could try to stream on an event filter on an ERC20 contract.

@Vypo
Copy link
Author

Vypo commented Aug 4, 2020

@roynalnaruto I believe that infura supports filters on their WebSocket interface. My previous comment was generated while running against infura's kovan endpoint, and it did output the event from my contract, but only while using the rt-core runtime.

If you could humor me and try to reproduce my issue by adding the rt-threaded feature to your tokio dependency in shuffler and reporting your results, I would very much appreciate it.

@roynalnaruto
Copy link
Collaborator

Let me try and use the rt-core feature and get back to you 👍

@gakonst gakonst reopened this Aug 4, 2020
@roynalnaruto
Copy link
Collaborator

@Vypo @gakonst So I tried the following filters:

  • empty filter
  • watch new blocks filter
  • smart contract event filter

With both rt-core and rt-threaded features for tokio, as well as without either of those features.

rt-threaded

With the rt-threaded feature, none of the filters seem to work.

rt-core

With the rt-core feature, the empty Filter::new() as well as watching for new blocks provider.watch_blocks() work! But the smart contract event filtering still fails to work, even for ERC20 token transfers. You can as well give it a try here on the test/erc-20 branch in the shuffler repo

neither

With both features disabled, the behaviour is the same as the one when rt-core was enabled.

@SamWilsn
Copy link
Contributor

Hey! I'm also having this issue. Does switching to async-std work?

@gakonst
Copy link
Owner

gakonst commented Aug 31, 2020

The fix in #61 should work, please re-open if you can still reproduce with latest master! Thank you for finding this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants