Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda