Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
How to filter an event by its parameters

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!