I'm trying to subscribe to an event, but also filter by its parameter. In other words, I want to only receive events that matches a specified value within id.
event PaymentMade(string id);
function pay(string id) public payable {
// process payment
emit PaymentMade(id);
}
// i.e. only receive the event if id == "something"
When I try web3.eth.subscribe, I'm able to get the event from a specific address and the specified topics only:
var subscription = web3.eth.subscribe('logs', {
address: '0x123456..',
topics: ['0x12345...']
}, function(error, result){
if (!error)
console.log(result);
});
But the problem is, I'm getting the all instances of the PaymentMade event regardless of what the parameter id is. I'm also unsure how to pass the parameter value to filter by.
If I use getPastEvents, I'm able to specify the filter value, but I"m still getting all events regardless of the parameter:
let options = {
filter: {
value: [id] //Only get events where the id matches a certain value
},
fromBlock: 0,
toBlock: 'latest'
};
try {
const result = await contract.getPastEvents('paymentMade', options)
} catch (error) {
console.log(error)
}
Finally, I've tried with and without indexed parameter for the PaymentMade event, but none seem to work.