Let's say I have a contract that fire an event PersonCreated(uint personId, bytes32 indexed name) every time a person is created.

To query for all the past events with name equal to Jason, we can use:

contract.getPastEvents('PersonCreated', {
    filter: {
        "name": [web3.utils.toHex("Jason") ]
    fromBlock: 0,
    toBlock: 'latest'
}).then((events)=> {
    console.log("Events: ", events)

[Q] Is it possible to create filter to query all event with name start with "J" instead?

1 Answer 1


According to func filterLogs in https://github.com/ethereum/go-ethereum/blob/7f74bdf8dded0e1ac3c01e043c2ed89d78f308cf/eth/filters/filter.go there is only a check for empty filter and equality (==), so the answer to your question is: no it's not possible (nevertheless, it would be cool to have that feature).

for i, topics := range topics {
    match := len(topics) == 0 // empty rule set == wildcard
    for _, topic := range topics {
        if log.Topics[i] == topic {
            match = true

If you want to filter by the starting letter, you'll have to define an additional parameter to you event. E.g.:

event PersonCreated(uint personId, bytes1 indexed firstLetter, bytes32 indexed name) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.