I have an event in my contract like this:
event SendEmail(address indexed fromAddress, address indexed toAddress, string ipfsHash);
Then from web3 I try to watch only those events where fromAddress matches some specific address:
var sendEvent = emailer.SendEmail({fromAddress: eth.accounts[0]},{fromBlock: 0, toBlock: 'latest'});
However, when I call watch() on the sendEvent object, I get all corresponding events, not only those where fromAddress is matched.
Have same issue
contract event like
event LogEvent(uint indexed lockId, string dataInfo, uint indexed version, uint16 eventType, address indexed sender, uint payment);
from web3 I try to watch like this:
event=contract.LogEvent({eventType: 1},{fromBlock: 0, toBlock: 'latest'});
And it's return me Logs with all status but not only with event type '1'.
The problem for me was actually that the parameter I was filtering by was not labeled as "indexed" in the deployed contract.
This seems to be the case in your code as well, so adding "indexed" before eventType should fix it. You will however have to unindex one of the 3 other parameters because there is a limit of maximum 3 indexed arguments per event.
I have the same issue with a indexed boolean.
My event looks like this:
event OnRent(bool indexed error, address indexed renter, uint start, uint end, string msg);
Now if I want to filter for the first parameter bool indexed error I observe a strange behaviour. If I filter with {error: true} I get the correct events, but if I filter with {error: false} I always get all events and not the filtered list.
// returns the correct filtered list of events
filterForNewRents = rentable.OnRent({error: true, {fromBlock: 0, toBlock: 'latest'})
// returns always all events
filterForNewRents = rentable.OnRent({error: false, {fromBlock: 0, toBlock: 'latest'})
Any ideas on this?
Seems I have the same issue. Specifying anything in the first argument (object, array etc.) doesn't seem to change the returned filter object in any way and I get all the events.
I have the argument indexed, double checked on the compiled JSON interface too.
If you already add indexed to event, but it was working by filtering event on web3. Please make sure events declaration is in top of contract inheritance, not the base contract.
You can check if indexed is working of ABI json file. For example
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "tokenId",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
"indexed" should be true.
@oney why is this a requirement? Is it a bug?
It seems that if I have Base -> Final class and Base declares an event with indexed param the Final class' event in the compiled info json will still say indexed: false
It this a truffle bug maybe?
@almindor It's not a requirement. Yes, I think that is a bug.
Version 0.20.x got his last maintenance release with v0.20.7. Please update your code to the latest 1.0 version of Web3.js. Further details about the current project state are explained in the release announcement of version 1.0.0-beta.38.
The problem for me was actually that the parameter I was filtering by was not labeled as "indexed" in the deployed contract.
This seems to be the case in your code as well, so adding "indexed" before eventType should fix it. You will however have to unindex one of the 3 other parameters because there is a limit of maximum 3 indexed arguments per event.
@andrejc already have indexed before that parameter still not able to get events based on filters.
@oney contract ABI has indexed: true but still not working.
Most helpful comment
The problem for me was actually that the parameter I was filtering by was not labeled as "indexed" in the deployed contract.
This seems to be the case in your code as well, so adding "indexed" before eventType should fix it. You will however have to unindex one of the 3 other parameters because there is a limit of maximum 3 indexed arguments per event.