Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda