Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event filters do not ignore null non-indexed parameters #305

Closed
Destiner opened this issue Oct 13, 2018 · 10 comments
Closed

Event filters do not ignore null non-indexed parameters #305

Destiner opened this issue Oct 13, 2018 · 10 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@Destiner
Copy link

Suppose I have following contract:

pragma solidity 0.4.25;

contract Events {
    event LogSomething(int hup, int indexed two, bool three, address indexed four);
    
    function something(int _hup, int _two) public {
        emit LogSomething(_hup, _two, true, msg.sender);
    }
}

I want to catch events, but only those which has two equal to, say, 2. I try to accomplish that with code:

const infuraProvider = new ethers.providers.InfuraProvider('rinkeby');
const contractAddress = '0x175f3477dfccc5a1e44c486bf9f26a963bdd2b74';
const contract = new ethers.Contract(contractAddress, eventsAbi, infuraProvider) as Events;
const specificFilter = contract.filters.LogSomething(null, 2, null, null);
console.log(specificFilter);
contract.on(specificFilter, (e) => {console.log(`specific filter = ${e}`)})

But that doesn't show any event that is emitted, regardless of two value.

The events themselves seems to work ok, as this filter

const anyFilter = contract.filters.LogSomething(null, null, null, null);
contract.on(anyFilter, (e) => {console.log(`any filter = ${e}`)});

Shows all relevant emits.

@Destiner
Copy link
Author

I think I have a clue for why this happens. Let's look at these two filters with console.log.
Specific:

{ "address": "0x175f3477dfccc5a1e44c486bf9f26a963bdd2b74",
  "topics":
   [ "0xf6b983969813047dce97b9ff8a48cfb0a13306eb2caae2ef186b280bc27491c8",
     null,
     "0x0000000000000000000000000000000000000000000000000000000000000002" ] }

Any:

{ "address": "0x175f3477dfccc5a1e44c486bf9f26a963bdd2b74",
  "topics":
   [ "0xf6b983969813047dce97b9ff8a48cfb0a13306eb2caae2ef186b280bc27491c8" ] }

This null shouldn't be there.

It seems like it puts arguments into topics, regardless of whether they're indexed or not.

@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2018

Oh! That is quite possible! I though I fixed this, but maybe not. Can you verify you are on the latest version with console.log(ethers.version)? I’ll fix this today.

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Oct 13, 2018
@Destiner
Copy link
Author

I think I was initially on 4.0.4, and now I'm on 4.0.5, and the error seems to be there.

@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2018

Ok, I’ll fix it ASAP and publish the new version to npm.

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Oct 13, 2018
@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2018

Travis CI is running right now, once it is finished I will publish to npm. I've added your example as a test case, as well as a few others, but in the future I will add procedurally generated tests to be more thorough.

@ricmoo ricmoo changed the title Event argument filter doesn't work Event filters do not ignore null non-indexed parameters Oct 13, 2018
@ricmoo
Copy link
Member

ricmoo commented Oct 13, 2018

Published! Please let me know if you still have any problems, and feel free to re-open this issue.

Thanks! :)

@ricmoo ricmoo closed this as completed Oct 13, 2018
@Destiner
Copy link
Author

It works for me!

Thanks for such quick fix.

@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Dec 10, 2018
@ricmoo ricmoo added the fixed/complete This Bug is fixed or Enhancement is complete and published. label Jan 11, 2020
@jahanzaibrashid
Copy link

I am having the same issue

 const {address} = await getSigner();
    let abi = ["event WithdrawalInitiated(address indexed _l1Token, address indexed _l2Token, address indexed _from, address _to, uint256 _amount, bytes _data)"]
    const l2Provider = new ethers.providers.JsonRpcProvider(process.env.REACT_APP_L2_URL);

    const contract = new ethers.Contract("0x4200000000000000000000000000000000000010", abi, l2Provider);
    let filter = contract.filters.WithdrawalInitiated(
      '0x6D1c1B67F4767D47d85D28466a9f60F126f46C93', //_l1Token
      '0x6D1c1B67F4767D47d85D28466a9f60F126f46C93', //_l2Token
      '0xa7722c27a0eaaa4690358ee3d31a4d38f20c38a1', //from address
      '0xa7722c27a0eaaa4690358ee3d31a4d38f20c38a1', // to address
      null,
    );
    const events = await contract.queryFilter(filter)
    console.log("=>",events)

https://kovan-optimistic.etherscan.io/tx/0xc5acefbf957871a1f8f67dd37d1647ec5c613ddb76e5e8fa93d2b1f5f09ba967#eventlog
this is event logs link i want to get transactions those are ready to relay on l2 network and show them on page for user to claim there token. but i and gettign error that is blow
Error: cannot filter non-indexed parameters; must be null

@ricmoo
Copy link
Member

ricmoo commented Jul 16, 2022

@jahanzaibrashid Your _to is not indexed, you cannot filter by it.

@jahanzaibrashid
Copy link

jahanzaibrashid commented Jul 16, 2022

Yes i fixed it now am be able to get all 4 transactions those are done by my wallet address thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

3 participants