()
| 8 | load_dotenv() |
| 9 | |
| 10 | async def main(): |
| 11 | bearer_token = os.getenv("ENVIO_API_TOKEN") |
| 12 | if not bearer_token: |
| 13 | raise ValueError("ENVIO_API_TOKEN environment variable is required. Please set it in your .env file.") |
| 14 | |
| 15 | client = hypersync.HypersyncClient(ClientConfig( |
| 16 | url="https://eth.hypersync.xyz/", |
| 17 | bearer_token=bearer_token |
| 18 | )) |
| 19 | |
| 20 | # The query to run |
| 21 | query = hypersync.Query( |
| 22 | # only get block 20224332 |
| 23 | from_block=20224332, |
| 24 | to_block=20224333, |
| 25 | include_all_blocks=True, |
| 26 | join_mode=JoinMode.JOIN_ALL, |
| 27 | field_selection=hypersync.FieldSelection( |
| 28 | block=[BlockField.NUMBER, BlockField.TIMESTAMP, BlockField.HASH], |
| 29 | log=[ |
| 30 | LogField.LOG_INDEX, |
| 31 | LogField.TRANSACTION_INDEX, |
| 32 | LogField.TRANSACTION_HASH, |
| 33 | LogField.DATA, |
| 34 | LogField.ADDRESS, |
| 35 | LogField.TOPIC0, |
| 36 | LogField.TOPIC1, |
| 37 | LogField.TOPIC2, |
| 38 | LogField.TOPIC3, |
| 39 | ], |
| 40 | transaction=[ |
| 41 | TransactionField.BLOCK_NUMBER, |
| 42 | TransactionField.TRANSACTION_INDEX, |
| 43 | TransactionField.HASH, |
| 44 | TransactionField.FROM, |
| 45 | TransactionField.TO, |
| 46 | TransactionField.VALUE, |
| 47 | TransactionField.INPUT, |
| 48 | ] |
| 49 | ), |
| 50 | |
| 51 | ) |
| 52 | |
| 53 | print("Running the query...") |
| 54 | |
| 55 | # Run the query once, the query is automatically paginated so it will return when it reaches some limit (time, response size etc.) |
| 56 | # there is a next_block field on the response object so we can set the from_block of our query to this value and continue our query until |
| 57 | # res.next_block is equal to res.archive_height or query.to_block in case we specified an end block. |
| 58 | res = await client.get(query) |
| 59 | |
| 60 | print(f"Ran the query once. Next block to query is {res.next_block}") |
| 61 | |
| 62 | print(len(res.data.blocks)) |
| 63 | print(len(res.data.transactions)) |
| 64 | print(len(res.data.logs)) |
| 65 | |
| 66 | asyncio.run(main()) |
no test coverage detected