1

I have question regarding topic:. I'd want to query and filter for specific transaction below.

Transaction Recept Event Logs

Topics
-1st log-
0 - 0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c
1 - 0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d 
-2nd log-
0 - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
1 - 0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
2 - 0x000000000000000000000000cffdded873554f362ac02f8fb1f02e5ada10516f
-3rd log-
0 - 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
1 - 0x000000000000000000000000cffdded873554f362ac02f8fb1f02e5ada10516f
2 - 0x000000000000000000000000e83d30715569fa0ef6744e96c7103cc410b82e09
-4th log-
0 - 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1 ```

My code Problem: When I add 2nd log 0 on 3rd topics:, it gets me empty.

from web3 import Web3, HTTPProvider
from hexbytes import HexBytes
w3 = Web3(Web3.WebsocketProvider('my addresss....'))
event_signature_hash = Web3.keccak(text="eventName(uint32)").hex()
event_filter = w3.eth.filter({
    "fromBlock":"latest",
    'topics':['0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c', '0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d']
})

For transaction above I was able filter only 1st log only. And When I tried to add 2nd logs on topics it returns empty... Is there any way to filter whole log using topics?

How I did to get 2nd log 2 and 3rd log 2

    'topics': [
[
    '0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c',
    '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
    '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'
    ],
[
    '0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d',
    '0x000000000000000000000000539562e68e37041729d5a8084b4ce982b0398afd'
],
[
    '0x000000000000000000000000cffdded873554f362ac02f8fb1f02e5ada10516f',
    '0x000000000000000000000000e83d30715569fa0ef6744e96c7103cc410b82e09'
]
3
  • Please post in plain text (no links or images) what type of data your are trying to filter. Commented Nov 26, 2020 at 15:16
  • @goodvibration thanks for reply... I will edit post 1 sec Commented Nov 26, 2020 at 15:22
  • Please refrain from updating your question according to the given answers. If you have another question, then please post it as a separate answer. Commented Nov 27, 2020 at 7:52

1 Answer 1

1

From the official documentation:

Given a transaction log with topics [A, B], the following topic filters will yield a match:

  • [] “anything”
  • [A] “A in first position (and anything after)”
  • [None, B] “anything in first position AND B in second position (and anything after)”
  • [A, B] “A in first position AND B in second position (and anything after)”
  • [[A, B], [A, B]] “(A OR B) in first position AND (A OR B) in second position (and anything after)”

So in order to retrieve the 1st log and the 2nd log, you need to use:

'topics': [
    [
        '0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c',
        '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
    ],
    [
        '0x0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d'
    ]
]
2
  • You are legend. I think I might figure out how to do it ! thank you :D Commented Nov 26, 2020 at 16:01
  • if u wouldn't mind could u show me how to do 2nn log - 2 as well? I added another array after 2nd nested but seems to be not working... Commented Nov 26, 2020 at 22:23

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.