()
| 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 | # start from block 0 and go to the end of the chain (we don't specify a toBlock). |
| 23 | from_block=0, |
| 24 | # The logs we want. We will also automatically get transactions and blocks relating to these logs (the query implicitly joins them). |
| 25 | logs=[ |
| 26 | hypersync.LogSelection( |
| 27 | # We want All ERC20 transfers so no address filter and only a filter for the first topic |
| 28 | topics=[ |
| 29 | [ |
| 30 | "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" |
| 31 | ] |
| 32 | ] |
| 33 | ) |
| 34 | ], |
| 35 | # Select the fields we are interested in, notice topics are selected as topic0,1,2,3 |
| 36 | field_selection=hypersync.FieldSelection( |
| 37 | block=[BlockField.NUMBER, BlockField.TIMESTAMP, BlockField.HASH], |
| 38 | log=[ |
| 39 | LogField.LOG_INDEX, |
| 40 | LogField.TRANSACTION_INDEX, |
| 41 | LogField.TRANSACTION_HASH, |
| 42 | LogField.DATA, |
| 43 | LogField.ADDRESS, |
| 44 | LogField.TOPIC0, |
| 45 | LogField.TOPIC1, |
| 46 | LogField.TOPIC2, |
| 47 | LogField.TOPIC3, |
| 48 | ], |
| 49 | transaction=[ |
| 50 | TransactionField.BLOCK_NUMBER, |
| 51 | TransactionField.TRANSACTION_INDEX, |
| 52 | TransactionField.HASH, |
| 53 | TransactionField.FROM, |
| 54 | TransactionField.TO, |
| 55 | TransactionField.VALUE, |
| 56 | TransactionField.INPUT, |
| 57 | ], |
| 58 | ), |
| 59 | ) |
| 60 | |
| 61 | # start the stream |
| 62 | receiver = await client.stream(query, hypersync.StreamConfig()) |
| 63 | |
| 64 | decoder = hypersync.Decoder( |
| 65 | ["Transfer(address indexed from, address indexed to, uint256 value)"] |
| 66 | ) |
| 67 |
no test coverage detected