()
| 11 | DAI_ADDRESS = "0x6B175474E89094C44Da98b954EedeAC495271d0F" |
| 12 | |
| 13 | async def main(): |
| 14 | bearer_token = os.getenv("ENVIO_API_TOKEN") |
| 15 | if not bearer_token: |
| 16 | raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.") |
| 17 | |
| 18 | client = hypersync.HypersyncClient(hypersync.ClientConfig( |
| 19 | url="https://eth.hypersync.xyz/", |
| 20 | bearer_token=bearer_token |
| 21 | )) |
| 22 | |
| 23 | # The query to run |
| 24 | query = hypersync.Query( |
| 25 | # start from tip and get only new events |
| 26 | from_block=20519993, |
| 27 | # Select all logs from dai contract address |
| 28 | transactions=[hypersync.TransactionSelection(from_=[DAI_ADDRESS]), hypersync.TransactionSelection(to=[DAI_ADDRESS])], |
| 29 | # Select the fields we want, we get all fields we need for decoding the logs |
| 30 | field_selection=hypersync.FieldSelection( |
| 31 | transaction=[ |
| 32 | TransactionField.HASH, |
| 33 | TransactionField.INPUT, |
| 34 | ] |
| 35 | ) |
| 36 | ) |
| 37 | |
| 38 | decoder = hypersync.CallDecoder([ |
| 39 | "transfer(address dst, uint256 wad)" |
| 40 | ]) |
| 41 | |
| 42 | while True: |
| 43 | res = await client.get(query) |
| 44 | |
| 45 | if len(res.data.transactions) > 0: |
| 46 | # Decode the log on a background thread so we don't block the event loop. |
| 47 | # Can also use decoder.decode_logs_sync if it is more convenient. |
| 48 | decoded_calls = await decoder.decode_transactions_input(res.data.transactions) |
| 49 | for call in decoded_calls: |
| 50 | if call: |
| 51 | print(f"Call decoded: addr: {call[0].val}, wad: {call[1].val}") |
| 52 | |
| 53 | height = res.archive_height |
| 54 | while height < res.next_block: |
| 55 | print(f"waiting for chain to advance. Height is {height}") |
| 56 | height = await client.get_height() |
| 57 | time.sleep(1) |
| 58 | |
| 59 | # continue query from next_block |
| 60 | query.from_block = res.next_block |
| 61 | |
| 62 | asyncio.run(main()) |
no test coverage detected