Being "token" below a contract instance, i do:

token.getPastEvents('OperationEvent', {fromBlock:68000000, filter: {productId: '0xe69cc33407fbe7f7d9bcc423d83da743843bcae7e19a7d20bfd38170f30f53f0'}})


Error: invalid argument 0: hex has invalid length 160 after decoding; expected 32 for topic 

The hex string sent is the result of "web3.utils.sha3()" for the original string topic. If i request all events from that contract i can see that the topic reported in the event i'm looking for perfectly matches the hex string i'm sending.

I suppose i'm just generating the topic the wrong way, but can't find anything in the docs or googling. ¿Any clue on how to get this right (filtering past events of a contract by an string topic)?

1 Answer 1


you can try:

token.getPastEvents('OperationEvent', { fromBlock: 68000000, topics: [, '0xe69cc33407fbe7f7d9bcc423d83da743843bcae7e19a7d20bfd38170f30f53f0'] }).then((events: any) => { console.log(events); ).catch((error: any) => { console.log(error); });

topics[0] is empty for the 'address' index, and your "productId hex" should has the same index of your indexed "productId" param;

for example if your event is event OperationEvent(string indexed productId, ...) topic should be => topics: [, '0xe69cc33407fbe7f7d9bcc423d83da743843bcae7e19a7d20bfd38170f30f53f0']

if your event is event OperationEvent(indexed param, string indexed productId, ...) topic should be => topics: [, , '0xe69cc33407fbe7f7d9bcc423d83da743843bcae7e19a7d20bfd38170f30f53f0']

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.